test mysql query for no results

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

test mysql query for no results

 
0
  #1
Jan 28th, 2007
Hey, I'm running a mysql query, and would like to run a script if the query returns no results. But what do I use to test for no results?

Something like:

[PHP]

if (!$query) {

do this

}

[/PHP]

But just not sure how to implement it. Little help?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: test mysql query for no results

 
0
  #2
Jan 28th, 2007
  1. if(mysql_num_rows($result)==0){
  2. //do this
  3. }
Last edited by php_daemon; Jan 28th, 2007 at 6:21 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: test mysql query for no results

 
0
  #3
Jan 30th, 2007
Originally Posted by php_daemon View Post
  1. if(mysql_num_rows($result)==0){
  2. //do this
  3. }
Thanks, that was perfect.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: 1supergirl is an unknown quantity at this point 
Solved Threads: 0
1supergirl 1supergirl is offline Offline
Newbie Poster

Re: test mysql query for no results

 
0
  #4
Mar 16th, 2008
Originally Posted by php_daemon View Post
  1. if(mysql_num_rows($result)==0){
  2. //do this
  3. }
OMG, you helped me so much!! I am new to php, and I was tearing my hair out. Thank you, Thankyou,! You are my hero!!!!!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: jamesmjr is an unknown quantity at this point 
Solved Threads: 0
jamesmjr jamesmjr is offline Offline
Newbie Poster

Re: test mysql query for no results

 
0
  #5
Mar 6th, 2009
Will this work for odbc_num_rows also. I tried but I get the same message no matter what
  1. $sql="SELECT * FROM rac_master WHERE mrnumb='$mrnumb' AND racnumb='$racnumb' AND findetdate IS NULL";
  2. $resultx=odbc_exec($conna,$sql);
  3. if (odbc_num_rows($resultx)==0) {
  4. echo"Record Has Been Finalized";
  5. }
  6. odbc_close($conna);
Last edited by peter_budo; Mar 8th, 2009 at 7:03 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: test mysql query for no results

 
0
  #6
Mar 6th, 2009
Can't say for sure, but one way to find out would just be to test it. Echo that variable out and see what you get.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: jamesmjr is an unknown quantity at this point 
Solved Threads: 0
jamesmjr jamesmjr is offline Offline
Newbie Poster

Re: test mysql query for no results

 
0
  #7
Mar 6th, 2009
It returns "Record Has Been Finalized", even if the query statement is met. Does it matter what data type is being used in the table
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: test mysql query for no results

 
0
  #8
Mar 6th, 2009
Originally Posted by jamesmjr View Post
It returns "Record Has Been Finalized", even if the query statement is met. Does it matter what data type is being used in the table
Wish I could help you here. I'm a novice at this stuff. Maybe someone more experienced will chime in.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: jamesmjr is an unknown quantity at this point 
Solved Threads: 0
jamesmjr jamesmjr is offline Offline
Newbie Poster

Re: MSSQL and num_rows

 
0
  #9
Mar 9th, 2009
Turns out the odbc_num_rows will always return -1 when using MSSQL. I changed my connecton to mssql_connect and mssql_num_rows . Every thing is working fine now.

Example:
  1. $conn=mssql_connect('localhost','******','******');
  2. $msdb=mssql_select_db("DatabaseName",$conn);
  3. $sql="SELECT * FROM Table WHERE value='$variable' ";
  4. $result=mssql_query($sql,$conn);
  5. IF (mssql_num_rows($result)==0) {
  6. echo"What ever";
  7. }
  8. mssql_close($conn);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC