Jump to content

Displaying Pages


arunpatal

Recommended Posts

Hello,

 

in this script this page show product list.....

I set it to show 6 product on each page.....

Now i have go around 60 products in list and the

problem is that the script show only 6 pages link...

 

The page link changes like this

 

1page = /products.php?s=0&p=6

2page = /products.php?s=6&p=6

3page = /products.php?s=12&p=6

4page = /products.php?s=18&p=6

5page = /products.php?s=24&p=6

6page = /products.php?s=30&p=6

 

now when i type manually /products.php?s=36&p=6

i can see the product list move and show me product after 6th page

but the link is not appearing....

 

and what is more strange is that when i have only 4 product in my list

then also it show me link for 6pages....

 

when i click 2page or other link it echo: We have no products listed in our store yet

 

This is the code

 

<?php
// Connect to the MySQL database
include "script/connect_to_mysql.php";

$display = 6;

// 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:
$q = "SELECT COUNT( id ) FROM product AS p";
$r = @mysqli_query ($mydatabase, $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;
}
?>


<?php
// Make the links to other pages, if necessary.
if ($pages > 1) {

echo '<p>';

// Determine what page the script is on:
$current_page = ($start/$display) + 1;

// If it's not the first page, make a Previous link:
if ($current_page != 1) {
echo '<a href="products.php?s=' . ($start - $display) . '&p=' . $pages . '"><</a>';
}

 // Make all the numbered pages:
 for ($i = 1; $i <= $pages; $i++) {
	 if ($i != $current_page) {
	 echo '  <a href="products.php?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="products.php?s=' . ($start + $display) . '&p=' . $pages . '">></a>';
 }
 echo '</p>'; // Close the paragraph.
} // End of links section.
?>

Edited by arunpatal
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.