开发者

FOUND_ROWS() Fails in PHP

开发者 https://www.devze.com 2023-03-23 23:43 出处:网络
I need to retrieve thetotal count of records after executing a query. I tried like this <?php include_once \'common.php\';

I need to retrieve the total count of records after executing a query. I tried like this

<?php
include_once 'common.php';

ini_set("mysql.trace_mode", "Off");

$sql ="get_list(0, 40, 'Name', 'DESC', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)";

$con = mysqli_connect("localhost", "root", "");

mysqli_select_db( $con, "crash_table");

mysqli_query($con, $sql开发者_JAVA技巧);

$sql2= "SELECT FOUND_ROWS();";

$result = mysqli_query($con, $sql2);

$count = mysqli_fetch_array($result);

echo "Count=".$count[0];

?>

but the count is always 0. In the code get_list() is a procedure where 40 is the LIMIT.. Why is it so?


Is SELECT SQL_CALC_FOUND_ROWS the last statement in you stored procedure? Because manual says:

The row count available through FOUND_ROWS() is transient and not intended to be available past the statement following the SELECT SQL_CALC_FOUND_ROWS statement.


Example of using SQL_CALC_FOUND_ROWS :

SELECT SQL_CALC_FOUND_ROWS [ FIELDS NAME ] FROM [ TABLE NAME ] WHERE ........ [ORDER BY] LIMIT [ X,Y ];

SELECT FOUND_ROWS();


You could try using mysql_num_rows() to retrieve the number of entries.

0

精彩评论

暂无评论...
验证码 换一张
取 消