Jump to content

Recommended Posts

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"];

Link to comment
https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307962
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307974
Share on other sites

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

}
}

Link to comment
https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307975
Share on other sites

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']];

?>

Link to comment
https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1307978
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/255023-cart/page/2/#findComment-1308173
Share on other sites

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.