ການຈັດຕັ້ງ PHP mysql_num_rows()

ການຈັດຕັ້ງ ແລະ ການນໍາໃຊ້

ການຈັດຕັ້ງຄູ່ມູນ mysql_num_rows() ການກະທຳກັບຄູ່ມູນຈຳນວນຈາກຄູ່ມູນທີ່ມີຄູ່ມູນ.

Syntax

mysql_num_rows(data)
Parameter Description
data Required. Result set. This result set is obtained from the call to mysql_query().

Description

mysql_num_rows() returns the number of rows in the result set. This command is only valid for SELECT statements. To get the number of rows affected by an INSERT, UPDATE, or DELETE query, use mysql_affected_rows().

Tips and Comments

Note:If used mysql_unbuffered_query()Then mysql_num_rows() will return the correct value only after all the rows in the result set have been retrieved.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * FROM person";
$result = mysql_query($sql,$con);
echo mysql_num_rows($result);
mysql_close($con);
?>

Output similar to:

3