I found some coding on this web site to LIMIT the results of a query with uses Prev. 1 2 3... and Next Buttons. But I can't seem to get the Buttons to show up on the next page or on certain query which do have a lot of results returned.
I know it looks like a big mess, but hey its work and knowledge in progess.
I'm not very good at debugging, so any help will be appreciated.
Many Thanks in Advance!
case 0:
$charge=(1 + ($percent/100));
$query = "SELECT descr, cost*$charge as newcost, part_num, vend_code, manu_part FROM products WHERE UPPER(descr) LIKE '%$input%' LIMIT 10";
if (empty($offset) || $offset< 0) {
$offset=0;
}
if (empty($index)) $index=0;
$getrows = mysql_query($query);
$numrows = mysql_result($getrows,0);
if ($result = mysql_query ("$query")) {
while ($row = mysql_fetch_array ($result))
{
echo "<U>Product Description:</U> ".$row[descr]."<br><U>Manufactuer:</U> ".$row[vend_code]."<br><U>Manufactuer Part Number:</U> ".$row[manu_part]."<br><U>Our Part Number:</U> ".$row[part_num]."<br><U>Our Price:</U> ".$row[newcost]."<br><br>";
}
}
while ($result2=mysql_fetch_array($getrows)){
$index++; /* Increment the line index by 1 */
}
if ($numrows <= $limit) {
/* Added this statement so if the result shows less that or the
equal ammount of the limit to show nothing at all , to kill
the "1" that was just generated */
}
else {
// Don't display PREV link if on first page
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "<a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a>   ";
} /* I particularly like having the [Previous] on the first page
if it has enough results to display at all with my mod , just helps
set the over all structure of the navigation system its self
so ill just add this to the above if statement */
else echo "<b><font color=666666>[Previous]</font></b>   ";
/* If its not to your likeing simply comment it out */
// Calculate total number of pages in result
$pages = intval($numrows/$limit);
// $pages now contains total number of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// Now loop through the pages to create numbered links
// ex. 1 2 3 4 5 NEXT
for ($i=1;$i<=$pages;$i++) {
// Check if on current page
if (($offset/$limit) == ($i-1)) {
// $i is equal to current page, so don't display a link
echo " <b><font color=666666>$i</font></b> ";
} else {
// $i is NOT the current page, so display a link to page $i
$newoffset=$limit*($i-1);
echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n";
}
}
// Check to see if current page is last page
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
// Not on the last page yet, so display a NEXT Link
$newoffset=$offset+$limit;
echo "    <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n";
} /* Im doing the same thing here as i did in the [Previous] above */
else echo "   <b><font color=666666>[Next]</font></b>";
}
break;
I know it looks like a big mess, but hey its work and knowledge in progess.
I'm not very good at debugging, so any help will be appreciated.
Many Thanks in Advance!
case 0:
$charge=(1 + ($percent/100));
$query = "SELECT descr, cost*$charge as newcost, part_num, vend_code, manu_part FROM products WHERE UPPER(descr) LIKE '%$input%' LIMIT 10";
if (empty($offset) || $offset< 0) {
$offset=0;
}
if (empty($index)) $index=0;
$getrows = mysql_query($query);
$numrows = mysql_result($getrows,0);
if ($result = mysql_query ("$query")) {
while ($row = mysql_fetch_array ($result))
{
echo "<U>Product Description:</U> ".$row[descr]."<br><U>Manufactuer:</U> ".$row[vend_code]."<br><U>Manufactuer Part Number:</U> ".$row[manu_part]."<br><U>Our Part Number:</U> ".$row[part_num]."<br><U>Our Price:</U> ".$row[newcost]."<br><br>";
}
}
while ($result2=mysql_fetch_array($getrows)){
$index++; /* Increment the line index by 1 */
}
if ($numrows <= $limit) {
/* Added this statement so if the result shows less that or the
equal ammount of the limit to show nothing at all , to kill
the "1" that was just generated */
}
else {
// Don't display PREV link if on first page
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "<a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a>   ";
} /* I particularly like having the [Previous] on the first page
if it has enough results to display at all with my mod , just helps
set the over all structure of the navigation system its self
so ill just add this to the above if statement */
else echo "<b><font color=666666>[Previous]</font></b>   ";
/* If its not to your likeing simply comment it out */
// Calculate total number of pages in result
$pages = intval($numrows/$limit);
// $pages now contains total number of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// Now loop through the pages to create numbered links
// ex. 1 2 3 4 5 NEXT
for ($i=1;$i<=$pages;$i++) {
// Check if on current page
if (($offset/$limit) == ($i-1)) {
// $i is equal to current page, so don't display a link
echo " <b><font color=666666>$i</font></b> ";
} else {
// $i is NOT the current page, so display a link to page $i
$newoffset=$limit*($i-1);
echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n";
}
}
// Check to see if current page is last page
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
// Not on the last page yet, so display a NEXT Link
$newoffset=$offset+$limit;
echo "    <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n";
} /* Im doing the same thing here as i did in the [Previous] above */
else echo "   <b><font color=666666>[Next]</font></b>";
}
break;