-
mysql_num_rows query
$ID = $_GET['ID'];
$limit=2; // rows to return
$numres=mysql_query("SELECT * from fragrances WHERE ID=$ID ORDER BY title");
$numrows=mysql_num_rows($numres);
// 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( $numres )) {
// 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";
}
?>
there seems to be some sort of trouble when it comes to the 2nd/next page scenario and it's not limiting results to just 2 like it's supposed to
bear in mind, i know the table syntax is abysmal and i will be fixing it once i have got the functionality working. lol. snap with the $ID = $_GET['ID'];
Last edited by e1seix; 07-24-2007 at 10:59 AM.
-
-
OK, have discovered one thing at least, forgot to add the "ID=$ID&" following $PHP_SELF for all the subsequent page links. but i'm still stuck as to why the limit attribute isn't working properly. it should be limiting to just 2 products being displayed; instead it's displaying all
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks