PFMaBiSmAd Posted January 15, 2012 Share Posted January 15, 2012 What still does nothing? The only thing that few lines of code is for is to - // code to 'add' an item to the cart Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307956 Share on other sites More sharing options...
ecabrera Posted January 15, 2012 Author Share Posted January 15, 2012 ok i dont get it so i thought that the item was already added to the cart? would i just do this and try to get the add id $query = mysql_query("SELECT * FROM events WHERE id='$fd' LIMIT 1"); $row = mysql_fetch_assoc($query); $eventid = $row["id"]; $eventname = $row["eventname"]; $eventtype = $row["typeevent"]; $eventinfo = $row["eventinfo"]; $date = $row["date"]; $time = $row["time"]; $livetickets = $row["sale"]; $numtickets = $row["numtickets"]; $pricestudents = $row["studentsprice"]; $priceseniors = $row["seniorsprice"]; $priceadults = $row["adultsprice"]; $venues = $row["venue"]; $categorys = $row["category"]; Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307962 Share on other sites More sharing options...
searls03 Posted January 15, 2012 Share Posted January 15, 2012 one way, I wouldn't suggest doing, but could be done is set one session at the beginning, such as a random number session, ie a session that is a random number. then whenever an item is added to the cart, it is put into a database with the number to store the proper items. then when they check out, you could just clear all the rows that have that session. again, one way, but not my most recommended way. Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307974 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2012 Share Posted January 15, 2012 I think your question is - how do I display the current cart? <?php if(empty($_SESSION['cart'])){ echo "There are no items in your cart!"; } else { // cart is not empty $items = implode(',',array_keys($_SESSION['cart'])); // get a list of the item numbers // get the rows matching the item id's $query = "SELECT * FROM events WHERE id in ($items) ORDER BY some_column"; // order the data the way you want it to be displayed $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ // your code to display the information about each item in the cart // Note: $_SESSION['cart'][$row['id']] contains the quantity of each item that is in the cart } } Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307975 Share on other sites More sharing options...
ecabrera Posted January 15, 2012 Author Share Posted January 15, 2012 ok so overall my cart.php should look like <?php // code to 'add' an item to the cart if(isset($_GET['add'])){ $item_id = $_GET['add']; // your code that gets and validates the item id $quantity = $_POST['howMany']; // your code that gets and validates the quantity if(!isset($_SESSION[$item_id])){ // the item id is not already in the cart, insert it $_SESSION['cart'][$item_id] = $quantity; } else { // the item id is already in the cart, modify the quantity instead $_SESSION['cart'][$item_id] += $quantity; } } ?> <?php if(empty($_SESSION['cart'])){ echo "There are no items in your cart!"; } else { // cart is not empty $items = implode(',',array_keys($_SESSION['cart'])); // get a list of the item numbers // get the rows matching the item id's $query = "SELECT * FROM events WHERE id in ($items) ORDER BY 'id'"; // order the data the way you want it to be displayed $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ // your code to display the information about each item in the cart $eventid = $row["id"]; $eventname = $row["eventname"]; $eventtype = $row["typeevent"]; $eventinfo = $row["eventinfo"]; $date = $row["date"]; $time = $row["time"]; $livetickets = $row["sale"]; $numtickets = $row["numtickets"]; $pricestudents = $row["studentsprice"]; $priceseniors = $row["seniorsprice"]; $priceadults = $row["adultsprice"]; $venues = $row["venue"]; $categorys = $row["category"]; // Note: $_SESSION['cart'][$row['id']] contains the quantity of each item that is in the cart } } ?> </div> <?php echo $_SESSION['cart'][$row['id']]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307978 Share on other sites More sharing options...
PFMaBiSmAd Posted January 16, 2012 Share Posted January 16, 2012 my cart.php should look like... If that code produces the result you have defined that you want, then the answer would be yes. Programming is the ultimate do-it-yourself task (had to be very careful stating that), because only the programmer knows what he intended his code to do and only he knows if he was successful when he observes the result when he tests his code. Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1308173 Share on other sites More sharing options...
ecabrera Posted January 16, 2012 Author Share Posted January 16, 2012 i echo the sessions and it gives me the name array Quote Link to comment https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1308263 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.