I want to count the number of rows in a table (using PHP and Mysql) all of the count() functions I can find only return columns, or array features, is there a function to return the number of rows? Many thanks!
you can count the number of rows returned by a query. note that this function is deprecated... it has options on the docs page here.
You need to use mysqli_num_rows() :
$con=mysqli_connect("host","name","pass","database");
$sql="SELECT * FROM table_name";
$result=mysqli_query($con, $sql);
$rowcount=mysqli_num_rows($result);
$rowcount now stores the number of rows.
$count = mysql_num_rows($query);
将返回查询选择的行数,请确保您未在查询本身中使用count()
。
Depending if you are using mysql, mysqli or PDO query.
if mysql_query rkstar told you how to do it :
if mysqli_query : http://php.net/manual/fr/mysqli-stmt.num-rows.php
if PDO : do another query ! $rowCount = $db->query("SELECT FOUND_ROWS()")->fetchColumn();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.