How does php determine whether the query result of an SQL statement is null?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.