Right now I have:
Shop Front:
Code: Select all
<?php
ob_start();
// 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>Shop <?php print($_GET['shopid']; ?></title>
<link rel="stylesheet" href="css/styles.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css">
<!--
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
}
-->
</style></head>
<body>
<h1 align="center">Your Shopping Cart</h1>
<div align="center">
<?php
echo writeShoppingCart();
?>
</div>
<h1 align="center">Items In Our Store</h1>
<div align="center">
<?php
$sql = "SELECT * FROM books WHERE shopid = '{$_GET['shopid']}' ORDER BY id";
$result = $db->query($sql);
$output[] = '<ul>';
while ($row = $result->fetch()) {
$output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>';
}
$output[] = '</ul>';
echo join('',$output);
?>
</div>
</body>
</html>
Shopping Cart:
Code: Select all
<?php
ob_start();
// 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();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?><!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>Shopping Cart</title>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<h1 align="center">Your Shopping Cart</h1>
<div align="center">
<?php
echo writeShoppingCart();
?>
</div>
<h1 align="center">Please check quantities...</h1>
<div align="center">
<?php
echo showCart();
?>
</div>
<p align="center"><a href="index.php">Back to shop...</a></p>
</body>
</html>
Now since I have my database like this:
Item ID...........Name...........Picture URL.................Price..............Owner
111111...........Toast.................toast.jpg....................13.00.............User1
111112...........Eggs.................eggs.jpg......................34.54.............User1
------------------------------
111120...........Milk...................milk.jpg........................35.49.............User2
------------------------------
111124...........Milk...................milk.jpg........................44.99.............User1
------------------------------
------------------------------
111151...........Toast.................toast.jpg....................13.00.............Shop 10
111152...........Eggs.................eggs.jpg......................34.54.............Shop 10
How can I make it compatable? I know I need to get the shop ID and then make it into 'Shop'. $id then query for all of the item with that shop name next to it. But I don't know how to only list an item on the page one time, and then just add to its quanity, so it displays X Toast only once and X Eggs only once. (READ MY PREVIOUS POSTS FOR MORE INFO, OF MY GOALS)
I've been just using a simple database like this:
id...... title......... author...... price....... shopid
1....... Book1 ..... Author1..... 24.99 ......4
2....... Book2 ..... Author2..... 21.99 ......2
3....... Book3 ..... Author3..... 8.99 ........3
4....... Book4 ..... Author2..... 14.99 ......2
To get the basic code, but thats not the way the database I need to read from is setup. So what can I do?