www.webdeveloper.com
Results 1 to 3 of 3

Thread: Paging with PDO

  1. #1
    Join Date
    Apr 2006
    Posts
    219

    Paging with PDO

    Hi,

    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?


    Code:
    $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);
    $stmt->execute($degerler);
    $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.

    Many thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,152
    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.:
    PHP Code:
    $pageData array_slice($rows, ($pageNbr 1) * $numPerPage$numPerPage); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2006
    Posts
    219
    Hi, thanks for your reply. I checked array_slice on PHP manual understood what you mean.

    Many thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles