Click to See Complete Forum and Search --> : Checking for empty resultset from the database


difrad76
06-27-2006, 09:45 AM
Is the a quick and easy way of checking if my qurey returned any data from database?

I am trying to do this with this code:

$sqlSummary="select * from tbl_monitorSummary where monitor_Id='".$id."'";
$res=odbc_fetch_array($executeStatement);
if ($res!=null && $res==true)
print("We have got Data");
else
print("We don't Have data");

but it doesn't work, always says that we have got data :(.

Thanks

themarty
06-27-2006, 10:06 AM
but it doesn't work, always says that we have got data
it doesn't always say you have got data, if it return True it tells you that the query was succesful (i.e. it didn't generate any errors)

take a look at:
odbc_num_rows() (www.php.net/odbc_num_rows)

difrad76
06-27-2006, 10:08 AM
Thanks for the replay but I found my issue. There was nothing wrong with this snippet of code. I made a mistake before validation that's why it was screwing up.

The Little Guy
06-27-2006, 10:09 AM
I believe something like this will work.

$sqlSummary="select * from tbl_monitorSummary where monitor_Id='".$id."'";
$res=odbc_fetch_array($executeStatement);
$result = mysql_query($sqlSummary);
$numrows = mysql_num_rows($result);
if(!$result){
echo"No Results";
}
else{
echo"$numrows results found";
}