I am fetching records from database in PHP and MySQL and showing it into the jqgrid.
Now i request 1 page which encompass 10 rows data in first request.
to achieve that i fire one
query to get total number of records
and then calculate
totalpages
which contains all total records.
and second
query to fire limited records i.e. 1 to 10
and next time 11 to 20
and so on.
so the problem is every time i have to fire two queries one to fetch the total number of records and other to fetch limited rows for a grid.
is it possible to fire only one query to achieve above thing ?
to fetch record in a normal fashion the above scenario is fine but if i preform serch then i have to fire two queries one to fetch total number of rows that matches the criteria and other to fetch only limited rows that meets the criteria
Update
Well my limits to access rows is depends upon the total number of records so i dont see any option to fire only one query. Please look how my PHP code is counting limit
1) Fire the query to access total records
$selectMemberData = "SELECT * FROM tbl_member";
//some db code ...
// store the total records value
$count = $dbMemberData->numRows;
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = ( $limit * $page ) - $limit; // do not put $limit*($page - 1)
//Fire another query to fetch limited records
$selectMember = "SELECT * FROM tbl_member LIMIT " .$start.", ". $limit;
so my concern is when i use autocomplete search at that moment it would be pretty expensive to fire the two queries. and the issue is i have dependent on total records to get start
and end
limit