rvdb86 Posted December 6, 2007 Share Posted December 6, 2007 Hey hope some one can help me out... I have the following sql query to get rows from a table: $sql5="SELECT * FROM products WHERE products_id='$products_id'"; $result5=mysql_query($sql5) or die(mysql_error()); while ($row5 = mysql_fetch_array($result5)) { extract($row5); i want to echo a message if no rows are found... can anyone give me any suggestions, i would really apprecaite any help! Quote Link to comment https://forums.phpfreaks.com/topic/80496-if-no-rows-are-found/ Share on other sites More sharing options...
cooldude832 Posted December 6, 2007 Share Posted December 6, 2007 you should alwasy check for no rows on a select like this <?php $sql5="SELECT * FROM products WHERE products_id='$products_id'"; $result5=mysql_query($sql5) or die(mysql_error()); if(mysql_num_rows($result5)>0){ while ($row5 = mysql_fetch_array($result5)) { extract($row5); } else{ echo "No Results Found."; } Quote Link to comment https://forums.phpfreaks.com/topic/80496-if-no-rows-are-found/#findComment-408089 Share on other sites More sharing options...
Orio Posted December 6, 2007 Share Posted December 6, 2007 Before the loop: <?php if(mysql_num_rows($result5) == 0) { //No results } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/80496-if-no-rows-are-found/#findComment-408090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.