Pagination script link question
Posted: Wed May 23, 2012 5:00 am
Please am having problem with this pagination scripts. I needed to link to the next page and I don't know if the url is correct, please kindly help me check through.
Check the codes below:
Check the codes below:
Code: Select all
function products(){
require_once ('dbc1.php');
// Number of records to show per page:
$display = 10;
// Determine how many pages there are...
if (isset($_GET['p']) && is_numeric($_GET ['p'])) { // Already been determined.
$pages = $_GET['p'];
} else { // Need to determine.
// Count the number of records:
if (isset($_GET['product'])){
$prod = ($_GET['product']);
}
?>
<title><?php echo $prod; ?> | The MarketPlace</title>
<?php
$q = "SELECT COUNT(id) FROM products WHERE category = '$prod' ";
$r = @mysqli_query ($dbc, $q);
$row = @mysqli_fetch_array ($r, MYSQLI_NUM);
$records = $row[0];
// Calculate the number of pages...
if ($records > $display) { // More than 1 page.
$pages = ceil ($records/$display);
} else {
$pages = 1;
}
} // End of p IF.
// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric ($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
// Make the query:
$q = "SELECT * FROM products WHERE category = '$prod' LIMIT $start, $display ";
$r = @mysqli_query ($dbc, $q);
if ($r){
echo '<div align="center"><table cellspacing="2" cellpadding="5"
width="100%" style="border:solid; border-width:1px; " bgcolor="#CCCCCC"><tr align="center"><td><b>Product</b></td><td> <b>Description</b> </td><td><b>Phone No</b></td><td><b>Price</b></td></tr>
';
$bg = '#eeeeee'; // Set the initial background color.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
$imgurl = 'uploads/'.$row["image"].'';
echo '<tr bgcolor="' . $bg . '" align="center"><td><b>'.$row['prodname'].'</b><br>';
echo '<a href="display.php?id='.$row['id'].'&prod='.$row['category'].'"><img src= '.$imgurl.' width=100 height=80 border=0><br> <font size="-2">Click for more details...</font></a></td>' ;
echo '<td width="150" align="left" >' . $row['proddescr2'] . '</td><td align="left">Call Vendor on:<br>'. $row['phone'] . '</td><td align="left">N' . number_format($row['price'],2) . '</td></tr>';
}
echo '</table></div>';
}else
echo "No products found!";
if ($pages > 1) {
// Add some spacing and start a paragraph:
echo '<br /><p>';
// Determine what page the script is on:
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button:
if ($current_page != 1) {
echo '<a href="m_category.php?product=home&s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
}
// Make all the numbered pages:
for ($i = 1; $i <= $pages; $i++) {
if ($i != $current_page) {
echo '<a href="m_category.php?product=home&s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
} // End of FOR loop.
// If it's not the last page, make a Next button:
if ($current_page != $pages) {
echo '<a href="m_category.php?product=home&s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';
}
echo '</p>'; // Close the paragraph.
} // End of links section.
}