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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.