I don’t know why, but my pagination links appear twice.
I’ve checked to make sure I’m not `echo`ing the links twice. I’ve checked the `while` loop so it doesn’t echo the links each time a record is found, and I havn’t repeated any line twice.
Please, what am I missing?
**My code**
$totalpages) {
// set current page to last page
$typepage = $totalpages;
} // end if
// if current page is less than first page...
if ($typepage < 1) {
// set current page to first page
$typepage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($typepage - 1) * $rowsperpage;
$results = $mysqli->query("SELECT * FROM food WHERE food_type
= '$type_id' LIMIT $offset, $rowsperpage");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object()) {
$foo_id = $obj->food_id;
echo '
';
echo '';
echo '
'.$obj->food_title.'
';
echo '
';
echo "
£".$obj->food_price."
";
echo '
';
echo '
';
echo '
Add to Basket
';
echo '';
echo '';
echo '';
echo '
';
}
echo "window.open('order.php?type='$type_id','_self')
";
}
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($typepage > 1 & $count_type > 0) {
// show << link to go back to page 1
echo "
";
// get previous page num
$prevpage = $typepage - 1;
// show < link to go back to 1 page
echo "
";
} // end if
// loop to show links to range of pages around current page
for ($x = ($typepage - $range); $x < (($typepage + $range) + 1); $x++){
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $typepage) {
// 'highlight' it but don't make a link
echo "
";
// if not current page...
}
else {
// make it a link
echo "
";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($typepage != $totalpages) {
// get next page
$nextpage = $typepage + 1;
// echo forward link for next page
echo "
";
// echo forward link for lastpage
echo "
";
} // end if
/****** end build pagination links ******/
?>