aaronxbond Posted May 29, 2009 Share Posted May 29, 2009 ok so the problem that im having is that the color types are stored in the DB, and what im trying to do is get the value of the color to show up on the functions page. but whats shown on there is the colors that are stored in the items db. any insight? items.inc.php <?php if(isset($_GET['id'])){ $_id = intval($_GET['id']); $query = "SELECT * FROM items WHERE category_id=$_id"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ echo '<form action="cart.php?action=add" method="post">'; echo '<table cellpadding="10px" cellspacing="10px"><tr><td style="font-weight:bold;font-size:16px;">'; echo '<input type="hidden" name="name" value="'.$row['name'].'" />'.$row['name']; echo '</td><td style="color:#990000;font-weight:bold;">$'; echo '<input type="hidden" name="price" value="'.$row['price'].'" />'.$row['price']; echo '</td></tr><tr><td>'; echo '<img src="img/'.$row['image'].'.gif" class="item_thumbnail">'; echo '</td><td>'; echo '<select name="color">'.$row['color'].'</select>'; echo '<br /><br />'; echo $row['size']; echo '<br /><br />'; echo '<input type="hidden" name="id" value="'.$row['id'].'" />'; echo '<input type="image" src="" name="Submit" alt="Add to Cart" value="Submit" class="btn"/>'; echo '</td></tr></table>'; echo '<br /><br />'; echo '</form>'; } } else{ echo ''; } ?> cart.php 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 .= ','.$_POST['id']; } else { $cart = $_POST['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; functions.inc.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have '.count($items).' item'.$s.' in your shopping cart</p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table cellpadding="5" cellspacing="10">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM items WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); if($row['category_id'] == 1){ $type = 'Mens T-shirt'; } if($row['category_id'] == 2){ $type = 'Mens Sleeveless T-shirt'; } if($row['category_id'] == 3){ $type = 'Mens Reg. Cut Tank Tops'; } if($row['category_id'] == 4){ $type = 'Mens Stringer Tanks'; } if($row['category_id'] == 5){ $type = 'Headwear'; } if($row['category_id'] == 6){ $type = 'Misc.'; } if($row['category_id'] == 7){ $type = 'Womens T-shirt'; } if($row['category_id'] == { $type = 'Womens Tank Top'; } if($row['category_id'] == 9){ $type = 'Womens Pants & Shorts'; } $output[] = '<tr>'; $output[] = '<td colspan="4" style="font-weight:bold;">'.$type.' by '.$row['name'].'</td></tr>'; $output[] = '<tr><td rowspan="2"><img src="../img/'.$row['image'].'.gif" alt="img_thumb" width="75" height="75" /></td>'; $output[] = '<td>$'.$row['price'].'<br />Each</td>'; $output[] = '<td>Qty:<input type="text" name="qty'.$row['id'].'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td style="color:#990000;font-weight:bold;">$'; $output[] = '<input type="hidden" name="price" value="'.$row['price'].'" />'.($row['price'] * $qty).'</td></tr>'; $output[] = '<tr><td></td>'; $output[] = '<td><a href="cart.php?action=delete&id='.$row['id'].'" class="r">Remove</a></td>'; $total += $row['price'] * $qty; $output[] = '</tr><tr><td colspan="3"><hr /></td></tr>'; } $output[] = '</table>'; $output[] = '<p style="float:right;">Total: <span style="color:#990000;font-weight:bold;">$'.$total.'</span></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>Your shopping cart is empty.</p>'; } return join('',$output); } ?> Link to comment https://forums.phpfreaks.com/topic/160168-drop-down-session-issue/ Share on other sites More sharing options...
waynew Posted May 30, 2009 Share Posted May 30, 2009 I'm sorry but could you explain your problem a little better? What are these color types etc -why are you storing them? What are you getting at the moment? Link to comment https://forums.phpfreaks.com/topic/160168-drop-down-session-issue/#findComment-845614 Share on other sites More sharing options...
aaronxbond Posted June 2, 2009 Author Share Posted June 2, 2009 there are over 10 items, and they are various clothings for a wrestling shop. and the colors vary depending on what clothing. some have red and black and white and others are grey and red but not black or white. the cart.php is making a session when you select a product and making it an id each time you select an item, but im having trouble adding the value of the colors to the session. when i try to make it in a variable after the $_POST['color'] i get whatever color's are stored in the db. any thought? Link to comment https://forums.phpfreaks.com/topic/160168-drop-down-session-issue/#findComment-847987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.