Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for data in mysql array

Status
Not open for further replies.
May 22, 2002
63
GB
Hi,

I am trying to see if a mysql query has returned any values:

if (empty($returnedarray)){
Print "No info";
}Else{
Print "There are records"
}

But it doesn't seem to work?

Any ideas?

Cheers,

Anders
 
Yes, I've tried that but if there are no results return the value for the $returnedarray is literally nothing (not even '0' when i print it to screen), but the empty check fails??? Weird?
 
I don't know what you've done with $returnedarray or what it would contain if the query worked, much less what it would contain if the query didn't.

Empty() checks whether a variable has been set. If you've used it as the LH side of an assignment operation, it's been set. The value does not have to be printable -- FALSE is an example of this.

And the value in $returnedarray is most likely FALSE if it was used as the LH side of an assignment of mysql_fetch_array().

Again, use mysql_num_rows() if you want to see how many rows were returned by a query.

Otherwise, process the return a row at a time:

while ($returnedarray = mysql_fetch_array($reshandle))
{
//process data here
} ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top