I have an MySQL query which is seems to work fine with a PDO execute and I want to make paging to the results. I want to show the total number of results also. If I make paging by adding "limit :rownumber, :rowperpage" to the end of the query, I have to execute another query to get the total count number. If I don't, I don't know how to make paging. Any ideas?
$searchquery = "Select propertycode,title,price,currency,altbolgeadi,bolgeadi,description,bedrooms,bathrooms from urunler where bolgeID=:location and altbolgeID=:sublocation and price between :pricemin and :pricemax limit :sayfa, :gosterim";
$stmt = $db->prepare($searchquery);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = count($rows);
In above code, if I keep the limit section $rowcount becomes the limit given to MySQL. If I don't, I don't know how to make paging with the $rows results.
02-08-2013, 10:57 AM
Since you're doing a fetchAll(), you could just do an array_slice() on the resulting array to get the desired page data, e.g.: