homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

how to add simple pagination?
for my first extract data page,
michael heraghty

10+ Year Member

Msg#: 3511535 posted 7:40 pm on Nov 22, 2007 (gmt 0)


I have just created my first database-driven page using PHP. It just takes data from a single table, and gives the user certain ways to order the data.

However, all the data is coming out on a single web page, which is too long.

Can anyone show me how to add some simple pagination? Here is the code.

Advice much appreciated (including any errors you see)!

/* This script gets listings from the database */
$db = mysql_connect("x", "y", "z");
if (!$db)
die('Could not connect: ' . mysql_error());
mysql_select_db("x", $db);

$orderby = $_GET["orderby"];
$selectcategory = $_POST[selectcategory];

/* If the user has clicked an 'ordered by' link*/
if ($orderby == 'category'):
$sql = "SELECT * FROM localfood ORDER BY category";
elseif ($orderby == 'name'):
$sql = "SELECT * FROM localfood ORDER BY name";

//if the user has chosen a category from the drop-down
elseif (!empty($selectcategory)) :
$sql = "SELECT * FROM localfood WHERE category ='".$selectcategory."'";
$sql = "SELECT * FROM localfood ORDER BY name";

/*Process the query and build the html table*/
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
print("<tr><td> ");

print("<tr><td><strong>Category:</strong> ");

print("<tr><td><strong>Address:</strong><br />");

print("<tr><td><strong>Phone:</strong> ");
printf("<tr><td><strong>Email:</strong> <a href=\"mailto:%s\">%s</a></td></tr>\n",
$row["email"], $row["email"]);
printf("<tr><td><strong>Web:</strong> <a href=\"%s\">%s</a>\n",
$row["web"], $row["web"]);
print("</td></tr>\n<tr><td><strong>Details:</strong><br />");



michael heraghty

10+ Year Member

Msg#: 3511535 posted 11:43 am on Nov 23, 2007 (gmt 0)

Update: for anyone who's interested, I found this simple pagination script


[edited by: dreamcatcher at 5:09 pm (utc) on Nov. 23, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved