•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 426,478 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,207 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 1011 | Replies: 3
![]() |
•
•
Join Date: Jul 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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> \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> \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
<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> \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> \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
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Clean Previous Next Script for MySQL results (PHP)
- Arrrgggghhhh... Radio Buttons are the bain of my life! Can someone please help. (ASP)
- Query multiple tables with duplicate data (MySQL)
- Dynamic Next/Prev Buttons in PHP/MySQL (MySQL)
- vBulletin mod_rewrite for vB 3.0.7 (Existing Scripts)
- Please Help!!! MOD function (ASP)
Other Threads in the MySQL Forum
- Previous Thread: Step Y Step Mysql Tutorials
- Next Thread: Hybrid Environment


Linear Mode