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:
Unfortunately, your browser does not support inline Frames! Click here to view this page in a new window
Download:
Usage note:
- Download numlinks.zip
- Extract it and upload all files to your webserver (run the numlinksexample.php to see how it works)
- You have to import the numlinkfuctions.php with require_once(’numlinkfunctions.php’); into your script.
- Also import the numlinkstyle.css in your HTML header with <link rel=”stylesheet” type=”text/css” href=”numlinkstyle.css”>
- 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.
May 18th, 2009 at 7:42 am
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!
May 18th, 2009 at 11:40 am
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
…
June 8th, 2009 at 4:31 pm
Great work in my opinion :)
Hope you can work on a few more tools/scripts
yours Sonnenspeer
June 13th, 2009 at 4:41 am
How I can get the numlinkfunctions.php file?
Thanks for your help.
June 15th, 2009 at 11:30 am
Sorry, I uploaded the wrong script. Now you can download the right one.
July 26th, 2009 at 5:57 pm
Nice script..
Thanks for this script
September 4th, 2009 at 10:46 am
Plz help me i dont understand the script
September 11th, 2009 at 7:43 am
Thx for this great script! it´s so easy to customize. rescued my day and saved a lot of work! ;-)
jens
September 13th, 2009 at 11:29 am
this script is amazing!!!
thank you very much!!!
February 25th, 2010 at 2:30 pm
How can I realize this script to
import an count data from .csv ???
please help !!!
February 25th, 2010 at 2:41 pm
Try this: http://php.net/manual/en/function.fgetcsv.php
February 25th, 2010 at 4:22 pm
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’);
?>
February 25th, 2010 at 7:40 pm
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