A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include an SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:
[code language=”php”]
$qString = "SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10";
$cntStr = "SELECT FOUND_ROWS()";
$result = mysqli_query($link, $qString) or die(mysqli_error($link));
$cnt = mysqli_query($link, $numString) or die(mysqli_error($link));
$cnt = mysqli_fetch_array($cnt);
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *