Paging not working properly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Leland
Forum Newbie
Posts: 2
Joined: Thu Jan 23, 2003 10:08 pm
Location: Pasadena

Paging not working properly

Post by Leland »

I'm having trouble with the paging section of a script that I've used successfully before.
Here's the site:
http://www.lissadesigns.com
Click on the 'Pansy' collection and then try the 'next' or '2' link at the bottom. It shows the correct variables passing through ($start, $num_results, and $num_pages), but it just shows the first 10 items again instead of the next nine that should show. Here's the paging section of the script:

Code: Select all

// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo '<div align=center>	<p>';

// Determine what page the script is on.	
if ($start == 0) {
$current_page = 1;
} else {
$current_page = ($start/$display_number) + 1;
}

// If it's not the first page, make a Previous button.
if ($start != 0) {
echo '<a href="jewelrycollections.php?start=' . ($start - $display_number) . '&collectionname=' . $collectionname . '&num_pages=' . $num_pages . '&num_results=' . $num_results . ' ">Previous</a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
$next_start = $start + $display_number;
if ($i != $current_page) { // Don't link the current page.
echo '<a href="jewelrycollections.php?start=' . (($display_number * ($i - 1))) . '&collectionname=' . $collectionname . '&num_pages=' . $num_pages . '&num_results=' . $num_results . ' ">' . $i . '</a> ';
} else {
echo '<b><u> ' . $i . '</b></u>' . ' ';
}
}

// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="jewelrycollections.php?start=' . ($start + $display_number) . '&collectionname=' . $collectionname . '&num_results=' . $num_results . '&num_pages=' . $num_pages . ' ">Next</a> ';
}
Any ideas why this isn't working correctly?
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

are those items separate entries in a database? if so what databse. Because your code is way to complicated for what you need.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you read this because it may have some bearing on the problem:
viewtopic.php?t=511

Mac
Leland
Forum Newbie
Posts: 2
Joined: Thu Jan 23, 2003 10:08 pm
Location: Pasadena

fixed it!

Post by Leland »

As I was falling asleep last night, the answer came to me:
Unlike previous uses of this paging script, this time I'd written it as a function and put it in an include file--what I'd neglected to do was feed the $start, $num_pages, and $num_results variables into the function along with the collection name variable. Once I did that this morning, all worked perfectly.

Thanks. :D
Post Reply