Jump to content

Recommended Posts

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 &#0183; 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?

Link to comment
https://forums.phpfreaks.com/topic/191882-shopping-cart-php-script-problems/
Share on other sites

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.