Array not returning as empty

In debugging someone else’s CMS I have a situation where I need to tell whether query returned an empty set or not. The code below is resulting in a set that is NOT empty, even though it should be returning an empty set.

$sqlStrHlt = "SELECT MemberInfo.ID,Caption,FirstName,LastName,MemberPhoto,Company,BrokerName,Broker FROM Highlights,MemberInfo,Brokers WHERE MemberInfo.ID=Member AND Brokers.ID=MemberInfo.Broker ORDER BY LastName,FirstName";
	$highlight=mysql_query($sqlStrHlt, $TEST) or die(mysql_error());
$htoggle=1;
	if (empty($highlight)) {
	$htoggle=0;
	}

The table Highlights is completely empty.
If I run this query from phpMyAdmin it results in a empty set.
However my results from the above implementation doesn’t return empty.

If I run var_dump on this it returns:

resource(6) of type (mysql result) 

I’ve tried a separate query with simply on the Highlights table and it still shows as not empty. This is below:

$sqlStrHlt = "SELECT * FROM Highlights";
	$Highlights=mysql_query($sqlStrHlt, $TEST) or die(mysql_error());
	$htoggle=1;
	if (empty($Highlights)) {
	$htoggle=0;
	}

Any ideas?
Need something else from me?
Thank you in advance.

Thanks for the help & the info.
I enjoy all things SitePoint so it’s heartening to see that the forums have an active and helpful community as well.

Thanks again!

A mysql_query always returns a resource.

If you want to see if it’s ‘empty’ or not, you check how many rows are returned.

$sqlStrHlt = 'SELECT * FROM Highlights';
$Highlights = mysql_query( $sqlStrHlt ) or die( mysql_error() );
$htoggle = ( mysql_num_rows( $Highlight ) > 0 ) ? 1 : 0;

That last line of code sets $htoggle to 1 if there are 1 or more rows, otherwise it sets $htoggle to 0.

Here’s a link to the Ternary Operator manual page if you haven’t come across the above syntax.

You may find it useful to write a function which returns all of the rows in a result set:

function GetAllRows($QueryString){
    $Result = MySQL_Query($QueryString) or return false;
    $ReturnArray = array();
    while( $Row = MySQL_Fetch_Assoc( $Result ) ){
        $ReturnArray[] = $Row;
    }
}

Then just count() that.