Search code examples
phpmysqllimit

Display total records found - php


Well i have a query which gives me couple of records.

$sql = "SELECT * FROM tablename WHERE..... LIMIT $limit";//getting dynamic limit values.

This gives me.

$sql = "SELECT * FROM tablename WHERE..... LIMIT 61,10";
$res=parent::_executeQuery($sql);
$rs=parent::getAll($res);
return $rs;

Here total records found is 61, out of which only just 10 record is returning. I need to display the total record. i,e 61 in my HTML file.

How do i able to get the total records?


Solution

  • If you want to limit the result set using LIMIT you'll have to run a second separate query along the lines of "SELECT COUNT(*) FROM tablename WHERE...". Either that or just remove the LIMIT.