How does PHP determine if the query result of an SQL statement is empty

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