How to know that the query result is 0 records

Source: Internet
Author: User
How do I know that the query result is 0 records
I want to query the database before inserting the record, there is no this record, in fact, my database table does not meet the certificatetype= ' HDFJ ' record
$sql = "SELECT * FROM Customers where certificatetype= ' HDFJ '";
$result =mysql_query ($sql);
if (! $result)
Die Mysql_error ();
Else
{
What should we do here to know if there is a record in the database?
Why do I have to output 1 of all two statements below?
echo Count (Mysql_fetch_row ($result));
echo count ($result);

}

------Solution--------------------
Mysql_num_rows () Gets the number of rows in the result set.
The reason for returning 1 is due to the special count (). If you say that the database does not have this record, mysql_fetch_row ($result) should return false. and
$result = count (false);
$result = = 1
------Solution--------------------
echo mysql_num_rows ($result)//Returns the number of rows for the query.
------Solution--------------------
discuss
Mysql_num_rows () Gets the number of rows in the result set.
The reason for returning 1 is due to the special count (). If you say that the database does not have this record, mysql_fetch_row ($result) should return false. and
$result = count (false);
$result = = 1

------Solution--------------------
PHP code
//what should be done here to know if there is a record in the database? Echo mysql_affected_rows ();//or Echo mysql_num_rows ($result); 
------Solution--------------------
The first parameter in the count () function should be an array or object. If var is isn't an array or ..., 1 would be returned. " Refer to the PHP Manual:
http://cn2.php.net/manual/en/function.count.php
------Solution--------------------
Mysql_num_ Rows is the Count
Mysql_fetch_array he mysql_fetch_rows returns an array of
  • 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.