PHP, MySql - Blank results

Hello.

How Can I check if mysql return blank results without using mysql_row_num?

Example:
$results = mysql_query($sql);

if(mysql_row_num($results)) > 0) {

}

What are you adverse to using [fphp]mysql_num_rows[/fphp] ?

Row num count number of rows. This take time. Is isnt supported with parameter “MYSQLI_USE_RESULT”

Many results.

no, that’s not true

what takes time is retrieving all the rows from the database, and sending them over the connection from the database to php

once they’ve arrived in php, the function to count them is ridiculously fast

of course, retrieving all the rows from the database assumes you actually need them, for instance to print them all out

if you don’t actually need them, then retrieving them for the sole purpose of counting them is silly – you can get the database engine to count them instead (which is much, much faster), and send you a single value with the total number

Or you could use the mysqli object return… then num_rows is an already defined property of the result object…

Hello.

Thanks for answer.

But another way doesnt exist?

In ASP was very good way.

Example:


Set RS = Conn.Execute(SQL);

If NOT RS.EOF Then

  While

        Response.Write RS("OK")
    RS.MoveNext
    Loop

End If

This code doesn’t count nothing but just check if results EOF.

I dont need to count how many results will give but just know TRUE/FALSE if same results will return.

A comparable php version.


<?php
$rs = mysql_query($sql);

if(0 < mysql_num_rows($rs)){
  
  while($row = mysql_fetch_assoc($rs)){
    
  }
  
}
?>

dont even need the if, really… the while wont throw an error unless $rs was invalid.

I agree, but I thought a like-for-like comparison would be clearer. :slight_smile: