That is correct, this is exactly how I got total count.
Now, I have two pieces of code, consisting of search query and results output and results paging (below). In order for them both to work I must include this into QUERY string - LIMIT $offset, $limit
// search logic and data output >>
$sql = "SELECT * FROM myTbl WHERE 1 = 1";
$sql .= empty($_POST['q']) ? NULL : " AND var1 LIKE '%".$_POST['q']."%'";
$sql .= empty($_POST['q']) ? NULL : " AND var2 LIKE '%".$_POST['q']."%'";
if($searchResults = $db->get_results($sql)) {
foreach ( $searchResults as $search )
{
echo "RESULTS OUTPUT HERE";
}
} else {
echo "Nothing found";
}
// search logic and data output <<
// paging results >>
$total = count ($searchResults);
$pager = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
if ($total > $limit) {
if ($page != 1) // this is the first page - there is no previous page
echo "<a href='?mypage&page=".($page - 1)."'>previous</a> |";
for ($i = 1; $i <= $pager->numPages; $i++) {
if ($i == $pager->page)
if ($i == $pager->numPages) {
echo " $i";
} else {
echo " $i |";
}
else
echo " <a href='?mypage&page=$i'>$i</a> |";
}
if ($page != $pager->numPages) // this is the last page - there is no next page
echo " <a href='?mypage&page=".($page + 1)."'>next</a>";
}
// paging results <<
Since the actual place where I get $total is beneath QUERY string, I guess I'm at a loss how to pass it back up to make it work...