RSS Forums RSS
Please support our MySQL advertiser: Programming Forums
Views: 1115 | Replies: 3
Reply
Join Date: Jul 2007
Posts: 2
Reputation: e1seix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
e1seix e1seix is offline Offline
Newbie Poster

Prev/Next Buttons Query

  #1  
Jul 24th, 2007
Help me out guys. I am probably being such a bonehead but I can't figure out where I've gone wrong with this code for adding Next/Prev buttons to my pages:

<code>$ID = $_GET['ID'];

$limit=2; // rows to return
$numresults=mysql_query("SELECT * from fragrances WHERE ID=$ID ORDER BY title");
$numrows=mysql_num_rows($numresults);

// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}

// get results
$result=mysql_query("ima_link, title, size, rrp, £, SHO, cli_link, buy_link ".
"from fragrances WHERE ID=$ID ".
"ORDER BY title LIMIT $offset,$limit");

// now you can display the results returned
echo "<table border='0' cellpadding='5' cellspacing='0' width='500'>";
while($row = mysql_fetch_array( $numresults )) {
// Print out the contents of each row into a table
echo "<tr><td align='center' bgcolor='#ffffff' rowspan='2' valign='top' width='125'>";
echo $row['ima_link'];
echo "</td><td align='center' bgcolor='#ffffff' valign='top' width='250'><p class='main_title'>";
echo $row['title'];
echo "</p></td><td align='center' bgcolor='#ffffff' rowspan='2' valign='top' width='125'><p class='main_type'>";
echo $row ['size']. " ". $row['type'];
echo "</p><p class='main_rrp'>RRP £";
echo $row['rrp'];
echo "</p><p class='main_£'>DFUK £";
echo $row['£'];
echo "</p><p class='main_shop'>";
echo $row['SHO'];
echo "</p><p class='main_buttons'>";
echo $row ['cli_link']. $row['buy_link'];
echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' valign='top' width='250'><p class='main_manufacturer'>";
echo $row['manufacturer'];
echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' colspan='3' valign='top' width='500'><hr color='#999999' width='95%'></hr>";
echo "</td></tr>";
}

echo "</table>";
// include code to display results as you see fit

// next we need to do the links to other results

if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> &nbsp; \n";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";
}

// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}

?></code>

I've obviously left out the connection details for privacy and I know the table syntax is abysmal. i'm just trying to sort out the large functionality before i tackle the smaller issues. lol.

What appears to be wrong is the $limit and the subsequent offset pages. Here's an example for you all to muster over. You can see the limit is not reduced to "2" like it's supposed to be.

http://www.dogfightuk.com/untitled.php?ID=4548
http://www.dogfightuk.com/untitled.php?ID=4510
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 2
Reputation: e1seix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
e1seix e1seix is offline Offline
Newbie Poster

Re: Prev/Next Buttons Query

  #2  
Jul 24th, 2007
have discovered at least that i had forgotten to add "ID=$ID&" following the $PHP_SELF for all it's subsequent links. i'm still unsure as to why it's not limiting the products displayed however.

help!
Reply With Quote  
Join Date: Jan 2006
Posts: 223
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Prev/Next Buttons Query

  #3  
Jul 24th, 2007
If you really looking for answer, you probably need to post it in PHP forum...

If you have queries relating to database(MySQL) post here.

kath.
challenge the limits
Reply With Quote  
Join Date: Jan 2006
Posts: 223
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Prev/Next Buttons Query

  #4  
Jul 24th, 2007
If you really looking for answer, you probably need to post it in PHP forum...

If you have queries relating to database(MySQL) post here.

kath.
challenge the limits
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:24 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC