< Prev Next > - 1. 2. 3. page link PHP function - Easy to use!

Finished scripts, PHP Add comments

If you list hundred or thousand records from a database on your website, it is unconfortable to show all of these on one page. So I wrote a < 1. 2. 3. > link function in PHP to browse through the pages like browsing through google results with a previous and next link. It is also simple to customize the design. Just change the styles in the numlinkstyle.css stylsheet file.

Example:

Download:

Numlinks V1.0

Usage note:

  1. Download numlinks.zip
  2. Extract it and upload all files to your webserver (run the numlinksexample.php to see how it works)
  3. You have to import the numlinkfuctions.php with require_once(’numlinkfunctions.php’); into your script.
  4. Also import the numlinkstyle.css in your HTML header with <link rel=”stylesheet” type=”text/css” href=”numlinkstyle.css”>
  5. Insert the function numlinks($pagenum, $maxpage, $pages_visible, $scriptname, $get); with the following parameters into your PHP code:
    $pagenum: Number of the current page
    $maxpage: Number of all pages
    $pages_visible: Maximum number of pages to be displayed (usually a odd number)
    $scriptname: Optional - File to which a number links
    $get: Optional - to deliver custom GET parameters (e.g. foo=bar&email=bla@hotmail.com)

Any Questions? Leave a comment!
* If you like this script, and in case you want to support us, we would appreciate it if you put a link to http://blog.polymorph.at on your website.

13 Responses to “< Prev Next > - 1. 2. 3. page link PHP function - Easy to use!”

  1. Bryan - After5PC.net Says:

    How do I limit how many posts or items are displayed on each page? I can’t seem to find the setting on the script code you provided.

    Thanks for your help!

  2. admin Says:

    hi bryan,
    you have to manage this on your own. I think you already know how many items you have. so if you decide to display 10 items per page you have to do the following. I’ll explain it with items for a mysql database.

    //number of items per page, e.g. 10
    $dataperpage = 10;

    // if you click on a 1,2,3… the corresponding number is stored in $_GET["pagenum"];
    $pagenum = $_GET["pagenum"];

    // determine the total number of items in yourdatabase
    $query = ‘SELECT count(*) as itemcount FROM yourdatabase’;
    $result = mysql_query($query);
    $row = mysql_fetch_object($query);
    $itemcount = $row->itemcount;

    // calculate the total number of pages
    $maxpage = ceil($itemcount / $dataperpage);

    // query the items you want to display on the current page from the database
    $itemfrom = ($pagenum-1) * $dataperpage;
    $query = ‘SELECT * FROM yourdatabase DESC LIMIT ‘.$itemfrom .’ ,’.$dataperpage;
    $result = mysql_query($query);

    // display the 1,2,3 links
    numlinks($pagenum, $maxpage, 11, “yourscript.php”, “”);

    // display the results in a loop

  3. Sonnenspeer Says:

    Great work in my opinion :)
    Hope you can work on a few more tools/scripts

    yours Sonnenspeer

  4. dody Says:

    How I can get the numlinkfunctions.php file?

    Thanks for your help.

  5. admin Says:

    Sorry, I uploaded the wrong script. Now you can download the right one.

  6. odho Says:

    Nice script..
    Thanks for this script

  7. James Says:

    Plz help me i dont understand the script

  8. Jens Says:

    Thx for this great script! it´s so easy to customize. rescued my day and saved a lot of work! ;-)
    jens

  9. Michael Says:

    this script is amazing!!!

    thank you very much!!!

  10. Sandra Says:

    How can I realize this script to
    import an count data from .csv ???

    please help !!!

  11. admin Says:

    Try this: http://php.net/manual/en/function.fgetcsv.php

  12. Sandra Says:

    This is what I tried but it doesn´t work … Why ???

    I hope you can help me !!!

    <?php

    $wantedCells[] = “manufacturer”;
    $wantedCells[] = “number”;
    $wantedCells[] = “product”;
    $dataperpage = 3;

    $cellFormat["manufacturer"] = “##text##“;
    $cellFormat["number"] = “##text##“;
    $cellFormat["product"] = “##text##”;

    $row = 1;

    $handle = fopen (”example.csv”,”r”);

    $data = fgetcsv ($handle, 1000, “;”);
    if(is_array($data)) {
    foreach($data AS $cellNr => $cellName) {
    $cellNamesArray[$cellNr] = $cellName;
    }
    }
    while ( ($data = fgetcsv ($handle, 1000, “;”)) !== FALSE ) {
    $num = count ($data);

    $maxpage = ceil($num / $dataperpage);
    $itemfrom = ($pagenum-1) * $dataperpage;

    print “”;
    $row++;

    for ($c=0; $c < $num; $c++) {
    if(in_array($cellNamesArray[$c], $wantedCells)) {
    if($cellFormat[$cellNamesArray[$c]]) print str_replace(”##text##”, $data[$c], $cellFormat[$cellNamesArray[$c]]);
    else print $data[$c] . “”;
    }
    }
    }
    fclose ($handle);

    if ($_GET['page'] != “”) $page = $_GET['page'];
    else $page = 1;

    require_once(’numlinkfunctions.php’);

    numlinks($page, 25, 11, ”, ‘demoparam=useless’);
    ?>

  13. Sandra Says:

    Leute helft mir doch mal bitte …
    Wie verknüpfe ich ich das ganze.
    Ich kenne mich leider nicht so gut aus mit php.
    Es funktioniert zwar soweit alles. Aber es werden alle produkte aufgelistet und nicht nur 3 pro Seite wie ich es gerne hätte mit eurem script zum blättern auf die nächste seite. Ich habe soweit fast alles richtig eingefügt aber es werden nicht die gewünschten einstellungen angezeigt. Was mache ich falsch?

    LG Sandra

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in