这是存储过程
DELIMITER $$
BEGIN
SET @sql = concat(@sql ,'SELECT SQL_CALC_FOUND_ROWS ');
SET @sql = concat(@sql ,';');
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
SELECT found_rows();
END
调用存储过程的php。
$mysqli = new mysqli($databaseHostname1, $databaseUsername, $databasePassword);
if(!$mysqli) die('Could not connect: ' . mysql_error());
mysqli_select_db($mysqli, '$db');
if(!$mysqli) die('Could not connect to DB: ' . mysql_error());
if ($keywordParam != ''){
$mysqli->query("SET @p_keywordParam = " . "'" . $mysqli->real_escape_string($keywordParam) . "'");
}else{
$mysqli->query("SET @p_keywordParam = NULL");
}
$mysqli->query("SET @p_pageOffset = $pageOffset");
$result = $mysqli->query("CALL getInventory2(@p_keywordParam,@p_pageOffset)");
if(!$result) die("CALL failed: (" . $mysqli->errno . ") " . $mysqli->error);
然后我输出数据
NUMBER OF RESULTS: <? echo <<<<<<< FOUND ROWS HERE >>>>>>>>> ?>
PAGE 1 of ?
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
<? echo $row['FIRST_NAME']; ?>
<? echo $row['LAST NAME']; ?>
我需要的是while循环之前的存储过程中的found_rows计数,以便我可以设置分页。
答案 0 :(得分:0)
运行查询后,运行以下命令:
SELECT FOUND_ROWS()AS int_count