Jump to content

PHP paging the Simple way


benvalmont

Recommended Posts

What do you mean exactly by paging by numbers? What is it going to be used for?

 

If you mean page.php?value= then you can do it two ways. I prefer the switch method

 

Say you had index.php?id=1 and it was looking for the id number you would simply do:

 

switch ($_GET['id']) {
    
    case '1':
    default:
        echo "this is page 1";
    break;

    case '2:
        echo "this is page 2";
    break;

}

 

The default: is for setting that case as the default page. For more info check out http://www.php.net/switch

 

Hope this helps some.

 

 

You need to create a pager class (or script) that takes the total number of results, and the currnet page (if there is one) and gives you back the next page, previous page, and the cut of your results (i.e. from 20-30). You can take a look at Pear::Pager class which is part of the standard Pear build, and analyse what they've done. This should give you some ideas.

Your question is not clear enough and you never stated what database system you're using. I know what you're asking you want a search page, displaying search results with X number of results per page. We get what you are trying to do but you aren't stating what you need help on exactly. How much of the PHP language do you know?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.