How does php determine whether the query result of an SQL statement is null? The code is as follows: $ SQL & nbsp; = mysql_query (& nbsp; "select & nbsp; * & nbsp; from & nbsp; TV _video & nbsp; where & nbsp; title & nbsp; how does like & nb php determine whether the SQL statement query result is null?
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 "the record is empty ";
}
The test result is: "hello word!" is output no matter whether the record is empty or not! "And" empty record ", that is, the two conditions are true, which makes me very puzzled. how can I determine whether an 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 'empty record set ';
------ Solution --------------------
$ Result = mysql_query ("select * from TV _video where title like '% $ keyword %' limit $ offset, $ PageSize ");
If (count ($ result) <0)
{
Echo "no data query! ";
}
Try this way
------ Solution --------------------
$ Result = mysql_query ("select * from TV _video where title like '% $ keyword %' limit $ offset, $ PageSize ");
If (! Mysql_affected_rows ()){
Echo 'No Records ';
}
------ Solution --------------------
Description
Int mysql_affected_rows ([resource $ link_identifier])
Obtain the number of rows affected by the last INSERT, UPDATE, or DELETE query associated with link_identifier.