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