RE: [PHP] Passing by conditional IF statement...why?
Ryan A wrote: Hi, I have this simple code in my php script: * * * * * $res = mysql_query(SELECT product_id, now()-1 FROM .$tc._prods where cno=$cno AND product_id='$product_id' LIMIT 1); if($res) { $r = mysql_fetch_row($res); $product_id2 = $r[0]; $th_pres= $r[1]; echo debug echo; }else {echo No results, sorry;} * * * * * its working great when the data actually exists but when there are no matches it still executes the if($res) part instead of displaying No results, sorry. Why is that? or am I using the syntax wrong? Thanks, -Ryan You need to test the number of records being returned. By just using if ($res) you're simply ensuring that it is returning a valid resource. It is, but it's just that the resource has zero rows. Change the test such that it check the number of results to be = 1 and it should work. Cheers, Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Passing by conditional IF statement...why?
Ryan Because you are actually getting a result, a result with no records... Might be better to use http://au2.php.net/manual/en/function.mysql-num-rows.php instead Martin -Original Message- From: Ryan A [mailto:[EMAIL PROTECTED] Sent: Tuesday, 23 March 2004 11:37 AM To: [EMAIL PROTECTED] Subject: [PHP] Passing by conditional IF statement...why? Hi, I have this simple code in my php script: * * * * * $res = mysql_query(SELECT product_id, now()-1 FROM .$tc._prods where cno=$cno AND product_id='$product_id' LIMIT 1); if($res) { $r = mysql_fetch_row($res); $product_id2 = $r[0]; $th_pres= $r[1]; echo debug echo; }else {echo No results, sorry;} * * * * * its working great when the data actually exists but when there are no matches it still executes the if($res) part instead of displaying No results, sorry. Why is that? or am I using the syntax wrong? Thanks, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php