homepage Welcome to WebmasterWorld Guest from 107.22.45.61
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
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




msg:3511537
 7:40 pm on Nov 22, 2007 (gmt 0)

Hi,

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)!

<?php
/* 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."'";
else:
$sql = "SELECT * FROM localfood ORDER BY name";
endif;

/*Process the query and build the html table*/
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
print("<tr><td> ");
printf("<h3>%s</h3></td></tr>\n",
$row["name"]);

print("<tr><td><strong>Category:</strong> ");
printf("%s</td></tr>\n",
$row["category"]);

print("<tr><td><strong>Address:</strong><br />");
printf("%s</td></tr>\n",
$row["address"]);

print("<tr><td><strong>Phone:</strong> ");
printf("%s</td></tr>\n",
$row["phone"]);
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 />");
printf("%s</td></tr>\n",
$row["details"]);
}

?>


 

michael heraghty




msg:3511821
 11:43 am on Nov 23, 2007 (gmt 0)

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

<snip>

[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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved