How does PHP determine if the query result of the SQL statement is empty?
The code is as follows:
$sql =mysql_query ("select * from Tv_video where title like '% $keyword% ' limit $offset, $PageSize");
$result =mysql_fetch_array ($sql);
if (!empty ($result)) {
while ($result =mysql_fetch_array ($sql)) {echo "Hello word!"}
if (!empty ($result)) {
echo "Record is empty";
}
The test results are: "Hello word!" will be output regardless of whether the record is empty And "Record is empty", that is, two conditions are set up, which makes me very puzzled, how exactly to determine whether a SQL return result is empty?
------Solution--------------------
$result =mysql_query ("select * from Tv_video where title like '% $keyword% ' limit $offset, $PageSize");
if (mysql_num_rows ($result) < 1) echo ' Recordset is empty ';
------Solution--------------------
$result =mysql_query ("select * from Tv_video where title like '% $keyword% ' limit $offset, $PageSize");
if (count ($result) <0)
{
echo "Query no data! ";
}
Give it a try.
------Solution--------------------
$result =mysql_query ("select * from Tv_video where title like '% $keyword% ' limit $offset, $PageSize");
if (!mysql_affected_rows ()) {
Echo ' no record ';
}
------Solution--------------------
Description
int Mysql_affected_rows ([resource $link _identifier])
Gets the number of record rows affected by the most recent insert,update or DELETE query associated with Link_identifier.