Jump to content

Pagination needed


umraz

Recommended Posts

Hi

 

I needed pagination for this please help

 

<?php

 

 

$id = $_GET['id'];

 

 

      $queryitem = "SELECT * FROM item WHERE idsub = '$id' ORDER BY name";

$resultitem = mysql_query($queryitem);

while($dataitem = mysql_fetch_assoc($resultitem)){

?>

 

Data

<

 

<?php

}

?>

Link to comment
Share on other sites

Pagination occurs based on the amount of rows pulled out from the DB. First you must get that count, then you must run math based on that count for how many results you want per page. So if your query there pulls 20 records and you only want 5 per page, then your static max per page would be 5.. So then you want to count the total rows pulled by your query. So you can do that math. 5 / 20 = 4 so that means you should have 4 pages :)

 

Pagination isn't a quick one liner or even a few liner..

 

As such, your current query doesnt support the concept. As you need to limit your results you need to select where to get your results from (starting at which row, in accordance with that limit). You need to also compensate for what if you get 21 records, and only need to pull one record for that 6th page.

 

On another note, its better to come here and ask for help on what your stuck with. Not with what you want us to do for you instead. You will get more answers here if you simply give an actual problem rather than say I need this, please help.. something like that makes most of us think you dont want help achieving the desired goal, you just want one person to come along, do it.. and you just copy and paste it, then away you go :)

 

Not tryin to be mean, just informative..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.