Eddard Startk Posted March 23, 2007 Share Posted March 23, 2007 I have an example of an webshop. de webshop works as follow. you can put the information in one table and you can retrieve the information correctly. it wil al be shown in the cart en the checkoutpage. I am stuck for a little while know. Imagine i have a table called "clothes" and every piece of clothes could be available in multiple sizes. i would have the following tables: - clothes - size - clothes_size if people choose "like" a T-shirt. they should be able to select a size. I cannot seem to realize this. I can show the clothing and available sizes but when selecting clothes the size wil not be available in the card. the code is as follow: to add an item ------------------------------------------------------ php:<ahref=wagen_management.php?act=add&pid=".$item["artikel_code"].">add item</a> ?> cart_function.php: --------------------------------------------------- php:// add item to cart function add_item_to_cart($id,$quantity) { // set cookie and store value in session setstp(); // call database connect function db_connect(); // get product id from database global $mysql_tablename; $sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE artikel_code=".$id.""); $item = mysql_fetch_array($sel_products); // returns the number of rows in a result, if 1 item exists if 0 item doesn't exists. $num_rows = mysql_num_rows($sel_products); // if item exists then add item to cart if ($num_rows >= 1) { session_regenerate_id(TRUE); $_SESSION["cart"][$id][0] = $item["artikel_code"]; $_SESSION["cart"][$id][1] = $quantity; header ("location:".$_SERVER['HTTP_REFERER']); } } ?> cart_management.php ---------------------------------------------------------------------- php:if ($_GET["act"] == "add") { session_start(); include "cart_function.php"; //unserialize($_SESSION["cart"]); if (!isset($_SESSION["cart"])) { // add first item add_item_to_cart($_GET["pid"],1); } else if (array_key_exists($_GET["pid"], $_SESSION["cart"])) { // add 1 to quantity if item in cart already add_item_to_cart($_GET["pid"],++$_SESSION["cart"][$_GET["pid"]][1]); } else { // add any other items after first item add_item_to_cart($_GET["pid"],1); } } ?> ps. not my own code Link to comment https://forums.phpfreaks.com/topic/44057-webshop-cannot-retrieve-from-multiple-tables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.