By fhelmschrott on
Hi,
in my module i'm using several db_query() and i'd like to check for empty results... something like:
$result = db_query(....);
if(empty($result)) return;
doesn't seem to work. I don't know why exactly but it seems like there's still an object returned from db_query and empty() doesn't see this as empty.
any idea?
--
Frank
Comments
db_result?
http://api.drupal.org/api/function/db_result/6
You could use that to check if there is at least 1 result or not maybe?
did it!
that worked, thanks
if(!db_result($result)) return;Just a note for D7 :)
Since db_result() removed, then for D7 use:
Not working with Drupal 7
Undefined property: DatabaseStatementBase::$num_rows
count records as result of
count records as result of db_query 7.x?
you should try
$sql = "SELECT A WORSE CONTENT MANAGEMENT SYSTEM THAN DRUPAL" //(this should retrieve 0 results... :) joke)
$result = db_query($sql);
$how_many_rows = $result->rowCount();
Works Fine with Drupal 7
It's the only way I found to test the content returned by $result :
if($result->rowCount()==0) return;
Thank you gusantor !
Thanks florentcm, this worked
Thanks florentcm, this worked for me also.
kleinermann web design