huntrguy102 Posted February 12, 2010 Share Posted February 12, 2010 I have this PHP script that basically pulls from my MySql database. here is the code: <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM books ORDER BY author'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].': '.$row['Genre'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> My database is full of book data such as: title, author, price and genre. So my problem is not that the code doesn't work, it is that is jsut posts all 300 books all at once. Is there a way to have it show 10 at a time and then hit a next button to go to the next 10 and so forth, as well as a previous button? Quote Link to comment https://forums.phpfreaks.com/topic/191882-shopping-cart-php-script-problems/ Share on other sites More sharing options...
sader Posted February 12, 2010 Share Posted February 12, 2010 add LIMIT 0,30 in your query end. This will select first 30 rows from table starting from first one LIMIT 60,30 will return 30 rows starting from 60 To make page rule or what ever it's called u must pass some number via $_GET and then setup your query so that it would limit result from right offset in table Quote Link to comment https://forums.phpfreaks.com/topic/191882-shopping-cart-php-script-problems/#findComment-1011437 Share on other sites More sharing options...
huntrguy102 Posted February 12, 2010 Author Share Posted February 12, 2010 OK I tried the LIMIT 0, 30 and it works but I'm still a bit confused on what you're trying to say about changing to LIMIT 30, 60 Quote Link to comment https://forums.phpfreaks.com/topic/191882-shopping-cart-php-script-problems/#findComment-1011507 Share on other sites More sharing options...
fenway Posted February 16, 2010 Share Posted February 16, 2010 Then check the manual for how LIMIT works with a non-zero offset... Quote Link to comment https://forums.phpfreaks.com/topic/191882-shopping-cart-php-script-problems/#findComment-1013137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.