Jump to content

Shopping Cart PHP script problems


huntrguy102

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.