Pagination is fine, but the numbers go along the page 1 thru whatever. Sometimes, if there is 5,000 in the database it could be 200 some pages.... how would, or where would a <br> go in place?
Second problem, where is my error of why the words next ane previous don't print on the screen?
if (!($limit)){
$limit = 30; // Default results per-page.
}
if ( !$page or $page < 0 ) {
$page = 0; // Default page value.
}
$numresults = mysql_query("SELECT * FROM table"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query"); // modify the "Not Found" error for your needs.
exit();
}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows % $limit) {
$pages++; // has remainder so add one page
}
$current = intval($page/$limit) + 1; // Current page number.
if (($pages < 1)) {
$total = 1; // If $pages is less than one, total pages is 1.
} else {
$total = $pages; // Else total pages is $pages value.
}
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit; //If not last results page, last result equals $page plus $limit.
} else {
$last = $numrows; // If last results page, last result equals total number of results.
}
//escape from PHP mode.
?>
<html>
<head>
<title>Menu</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor=#FFFFFF>
<table width="100%" border="0" cellpadding="2">
<!--DWLayoutTable-->
<tr><td width="323" align="left">
<font size="1">Results per-page:
<a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=25">25</a></font>
</td>
<td colspan="2" align="left"> </td></tr>
<tr><td align="left">Showing Results <b>
<?=$first?>
</b> - <b>
<?=$last?>
</b> of <b>
<?=$numrows?>
</b></td>
<td width="324" align="left">Page <b>
<?=$current?>
</b> of <b>
<?=$total?>
</b></td>
<td width="324" align="left"> </td></tr>
<tr><td colspan="3" align="left" valign="top"> <div align="left"></div>
</font></td></tr>
<tr><td colspan="3" align="left"><!--DWLayoutEmptyCell--> </td></tr>
<tr><td colspan="3" width="130" align="left"><tr>
<td colspan="3" align="left">
<br><a href="whatevery.php">Back</a>
<?
//from here up things are fine.
$results = mysql_query("SELECT * FROM table
WHERE TypeCode LIKE 'SWEATSHI%'ORDER BY TypeCode ASC LIMIT $page, $limit");
if(mysql_error())
echo mysql_error();
for($i = 0; $i < $limit; $i++){
for ($count = 1; $row = mysql_fetch_assoc ($results);++$count) {
if ($count & 1) {
$color = "#CDB5CD";
$font = "white";
} else {
$color = "#DDA0DD";
$font = "black";
}
//just table info, things here work fine, won't print this.
//I think the errors might be below,
// but I cannot figure them out.
}
}
?>
<P></P>
<?
//$limitnum = 15;
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$this_document?query=$query&page=$back_page&limit=$limit\">back</a>\n");
}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page) {
echo("<b>$i</b>\n");
} // If current page don't give link, just text.
//elseif ($ppage < $page - $limitnum || $ppage > $page + $limitnum){}
else {
echo("<a href=\"$this_document?query=$query&page=$ppage&limit=$limit\">$i</a>\n");
}
}
if (!((($page+$limit) / $limit) >= $pages) &&
$pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$this_document?query=$query&page=$next_page&limit=$limit\">next</a>");
}
?>
</font></td></tr>
<tr><td colspan="3" align="left"><!--DWLayoutEmptyCell--> </td></tr>
<tr><td colspan="3" width="130" align="left"><tr>
<td colspan="3" align="left">
<br><font size=1><a href="#top">top of page</a></font>
</td>
</tr>
</table></body>
</html>
Last, when I do have 5,000 products and I get 200 pages, they all have products on them, well thats what I thought, until I clicked thru all of them, somewhere down the line they are empty pages, the products ran out, yet the pages kept printing, so something to do with the (if there is more data, print another page) is wrong, but cannot locate that either.
Thanks to anyone for their help
charles