PHP, PHP _, Web developer

Simple Paging in PHP

My first tutorial for PHP is simple page breaking of data. Basiclly I’ve set up a file which contains information about images in text file.

Data file looks like:
imagelocation1, imagedescription1
imagelocation1, imagedescription2


img1.jpg, Picture from sea
img2.jpg, Picture from cafe

and so on… PHP page loads data and show only info for 10 picture for the page that is choosen from GET variable in URL.
It’s just basic stuff and you can improve it to suite your needs, this is simple example so we don’t get too far from point and so you can learn other stuff while exploring this example.

Example page
ZIP file with data

EDIT: Links are updated! Sorry for keep you waiting…


16 thoughts on “Simple Paging in PHP

  1. pleocross says:

    How would you make it so that the numbers appear as well?

    ie Page 1 2 3 4

    And make it so they go to their corresponding page?

  2. mattk says:

    Re: Pelocross

    better late than never.. I made some changes to the original code’s variables (for my own use).. Although, I believe the strings still match up, double check to be sure. This is a very ‘simple/primal’ way of doing it.

    Place this between the IF statements for (previous page) (next page)

    for ($i = $page-4; $i =1){
    echo ““. ($i) .” “;

    echo ““. ($page+1) .” “;

    for ($i = 2; $i+$page < $maxpages+1; $i++){
    echo "“. ($page+$i) .” “;
    if ($i == 5){

    If you want to change how many page #’s are displayed. Increase the first ‘IF’ statment from $page-4 to whatever number you want


    Increase the IF that breaks… if ($i == 5) … to whatever value you want.

    I know this is a very primal way of doing it.. but gets the job done.

    FYI.. this will display 4 pages in front, and behind your current viewed page. It will also bold the current page your on.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s