Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Know when a MYSQL result is empty?
Old 02-22-2010, 08:44 AM Know when a MYSQL result is empty?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi guys,
This has been annoying me for over an hour now to no avail.

Ive got this

PHP Code:
        $chkquery "SELECT foo from foo WHERE foo = '$conffoo';";
        
$chkresult mysql_query($chkquery) or die(mysql_error());
                while(
$chkrow mysql_fetch_array($chkresult)){

                
$isit $chkrow['foo'];

                echo 
"isit = $isit \n";
                if (
$isit == "") {
                echo 
"Error This FOO $conffoo doesnt seem to be here \n";
                }else{
                echo 
"$conffoo is here \n";
                }
        }


Anyway,
What im doing is,
Im trying to match rows in a table , If that row is there then great.
If it isnt i need it to echo saying " Its not here!"

I cant seem to get it to work when it doesnt find a matching row.

Ie:
Its happy when it can find a matching row.

If it cant find a matching row it just doesnt seem to do the while..


Any thoughts?


-G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 02-22-2010, 08:59 AM Re: Know when a MYSQL result is empty?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Ok??

What exactly are you trying to do?????

because your code and query makes no logical sense at all.

Either your sql query is going to return rows, or it isn't, and if it returned one row or several rows then the specified column equalled the search value.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-22-2010, 09:10 AM Re: Know when a MYSQL result is empty?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Esessentaily im got 2 tables.


I need to check if X exists in Y table.

IE:

Go through every row in table 1
If X from table 1 exists in table 2 then all is good.
If not, Echo error

Then continue through each row in table 1.

It says its fine when it can find a matching row.
However when it doesnt return anything, i cant figure out how to mark that row as bad.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-22-2010, 09:16 AM Re: Know when a MYSQL result is empty?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Humm, considering im only expecting one row returned,

Ive tried.
$chkrow = mysql_fetch_array($chkresult);

rathen than using a while, and that seems happy.

There has to be a better way for me to achieve this.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-22-2010, 09:28 AM Re: Know when a MYSQL result is empty?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If it doesn't return anything the query failed and there is nothing to "mark as bad"

maybe something like this is what you are after?
$query = "SELECT COUNT(column) AS reccount FROM table WHERE column = 'value';"
// run SQL query

if row['reccount'] = 0{
echo('No records') ;
}

that's pseudocode not working code BTW.

IF reccount is > 0 matching records were found.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-22-2010, 09:47 AM Re: Know when a MYSQL result is empty?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Thanks chris,

That works fine,

Ive got it now so if it find more than 1 row it will do the "all is good code"

it its 0 then it runs the "Oh no its gone wrong code"


Thanks again for ya help.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-25-2010, 06:28 AM Know when a MYSQL result is empty?
Junior Talker

Posts: 1
Name: bidnz
Trades: 0
hiiiiiiiiiiiii
i think u need to check the query again.i think some problem in query.
after query u can check query.weather query is empty or not this can be done by using mysql_num_rows

i hope this will help u

thanks
masterblasters is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Know when a MYSQL result is empty?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60495 seconds with 12 queries