Yet another post about pagination.... <sigh>
But this one is different... honest !!
I can do the pagination setting the limit and offset for each page, etc, HOWEVER, can this be done cross tables ??
The answer of course is yes, but the answer is eluding me at this present moment...
For example...
<?php
$limit=8; // rows to return
if (empty($offset)) {
$offset=1;
}
$query=mysql_query("SELECT company FROM suppliers");
$company=mysql_fetch_array($company);
foreach ($company as $table)
{
$query2=mysql_query("SELECT COUNT(product) as product FROM $table");
$row=mysql_fetch_array($query2); //so $row[product] is the number of rows.
$numrows=$row[product];
$query2=mysql_query("SELECT product,price FROM $table LIMIT $offset,$limit");
while(list($product,$price)=mysql_fetch_row($query2))
{
echo "<tr><td>$product</td><td>$price</td></tr>";
}
}
print("<tr><td align=center>");
if ($offset!=1) { // bypass PREV link if offset is 0
$prevoffset=$offset-9;
print "<a href=\"$PHP_SELF?offset=$prevoffset\" title=\"Previous page\"><<</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows2/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows2%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=(($limit*($i-1))+1);
print "<a href=\"$PHP_SELF?offset=$newoffset\" title=\"Page $i\">$i</a> \n";
}
// check to see if last page
if (($offset+$limit)<$numrows2) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\" title=\"Next page\">>></a><p></td></tr>\n";
}
?>
Credits to whoever made the bottom code originally, amended but quite similar non the less.
This code will only do the offset for the first table in the sequence, and not the rest (it stops dead - but doesn't give an error).
If anyone has any experience with this and can push me along the right track, then please give us a hand..
Cheers,
Update:
The pagination works, but becasue it cycles through each of the tables, it tries to limit it per table not overall... this seems to be the stumbling block... any thoughts ???