Checking if query has records
Hi all, i have a query that i want to check to see if there are any records. What i have been given doesnt seem to be correct.
This is is a loop, i simply want to check if there is a record.
PHP Code:
$imgQuery = mysql_query("SELECT * FROM meltdown_images Where download_id='" . $myrow[1] . "'",$db);
while ($rowQuery = mysql_fetch_array($imgQuery));
// Records
} else {
// No records
}
Re: Checking if query has records
You can use mysql_num_rows() to check the number of records return from your query.
If you want to return only one record use "LIMIT 1" in your query so you don't return records you don't need.
Re: Checking if query has records
If all you want to do is check for records then alter your query
PHP Code:
$records = mysql_query('select count(*) from meltdown_images where `download_id` = '.(int)$myrow[1]);
$recordCount = mysql_result($records)[0];