In many scripts, programmers check if the SELECT query has returned any record before running the corresponding while loop as
$result=mysql_query("SELECT * From table WHERE column='XX'");
if(mysql_num_rows($result)>0) {
while($row=mysql_fetch_array($result)){
...
}
}
Is this check necessary or useful at all? because when not returning any record, the while loop will not cycle. Can checking the number of returned rows improve the performance?
you usually do it for the case where no rows have returned, and you simply want to print out a nice message for the user. if you only have a while loop, you’ll need to keep a counter and that can get ugly.
so it’s there mainly for the
😉