Page is a not externally linkable
michael_heraghty - 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)! <?php $orderby = $_GET["orderby"]; /* If the user has clicked an 'ordered by' link*/ //if the user has chosen a category from the drop-down /*Process the query and build the html table*/ print("<tr><td><strong>Category:</strong> "); print("<tr><td><strong>Address:</strong><br />"); print("<tr><td><strong>Phone:</strong> "); ?>
Hi,
/* 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);
$selectcategory = $_POST[selectcategory];
if ($orderby == 'category'):
$sql = "SELECT * FROM localfood ORDER BY category";
elseif ($orderby == 'name'):
$sql = "SELECT * FROM localfood ORDER BY name";
elseif (!empty($selectcategory)) :
$sql = "SELECT * FROM localfood WHERE category ='".$selectcategory."'";
else:
$sql = "SELECT * FROM localfood ORDER BY name";
endif;
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
print("<tr><td> ");
printf("<h3>%s</h3></td></tr>\n",
$row["name"]);
printf("%s</td></tr>\n",
$row["category"]);
printf("%s</td></tr>\n",
$row["address"]);
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"]);
}