TheJoey Posted October 1, 2009 Share Posted October 1, 2009 Hey guys i need a way to set a default value of a a product in my shopping cart to 1 at the moment its 0. Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/ Share on other sites More sharing options...
5kyy8lu3 Posted October 1, 2009 Share Posted October 1, 2009 I think we're gonna need to know a little more than that to help you out, and I'm not even sure you posted in the right sub-forum Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928092 Share on other sites More sharing options...
TheJoey Posted October 1, 2009 Author Share Posted October 1, 2009 well im just echoing a qty that ive stored ina session <?php echo $_SESSION["qty"][$key]; ?> just want to know if i can make it always echo 1 insted of 0 Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928099 Share on other sites More sharing options...
Alex Posted October 1, 2009 Share Posted October 1, 2009 <?php $_SESSION["qty"][$key] = 1; echo $_SESSION["qty"][$key]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928122 Share on other sites More sharing options...
trq Posted October 1, 2009 Share Posted October 1, 2009 echo isset($_SESSION["qty"][$key]) ? $_SESSION["qty"][$key] : '1'; Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928125 Share on other sites More sharing options...
TheJoey Posted October 1, 2009 Author Share Posted October 1, 2009 ahh sorry if i didnt explain myself well guys. i tend to do that sometimes. I have a shopping cart and when i add a item it displays item name : (Nothing here as 1) : price then when i click add again it adds it as item name : 1 : price where i want 1 to be a incremental Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928173 Share on other sites More sharing options...
trq Posted October 1, 2009 Share Posted October 1, 2009 Yeah, that helps heaps. Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928180 Share on other sites More sharing options...
TheJoey Posted October 1, 2009 Author Share Posted October 1, 2009 When im adding to my shopping cart. It is being display as an empty value, inside quantity when its really a 1. So then the incremental is then out of wack the next time i add a item. so if instead of it being display as 2 it is being displayed as 1. Because of the fact that its starting off as NULL. Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928187 Share on other sites More sharing options...
redarrow Posted October 1, 2009 Share Posted October 1, 2009 you can set the database to a default number, or you can use array_push() function. or is it array_unshift forgot now..... your see all the array functions available in php. http://uk3.php.net/manual/en/function.array-unshift.php Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928189 Share on other sites More sharing options...
trq Posted October 1, 2009 Share Posted October 1, 2009 When im adding to my shopping cart. It is being display as an empty value, inside quantity when its really a 1. So then the incremental is then out of wack the next time i add a item. so if instead of it being display as 2 it is being displayed as 1. Because of the fact that its starting off as NULL. So post the relevant code that creates an item in your cart. We can't do anything but post examples without the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928227 Share on other sites More sharing options...
TheJoey Posted October 1, 2009 Author Share Posted October 1, 2009 <html> <body> <?php if (isset($_POST['submit'])) { if($_SESSION['item']==$_POST['h1']) { $_SESSION['qty'] = $_SESSION['qty'] + 1; } else { $_SESSION['item'] = $_POST['h1']; $_SESSION['price']= $_POST['h2']; } $_SESSION['itemprice'][$_SESSION['item']] = $_SESSION['price']; $_SESSION['itemqty'][$_SESSION['item']] = $_SESSION['qty']; $_SESSION['itemname'][$_SESSION['item']] = $_SESSION['item']; } ?> <table> <tr> <td> </td> <td>ITEM info here</td></tr> <tr><td><form action="cartpost.php" method="post"><input type="submit" name="submit" value="ADDING"/><input type="hidden" name="value" value="itemid" /><input type="hidden" name="value1" value="7000"/></form> </td></tr> </table> <a href="cart.php">View your cart</a> </body> </html> this just outputs into the minicart <?php echo "The shopping cart looks as follows:--"; if(isset($_POST['submit'])) { $itemname = $_POST['value']; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='1'>"; echo "<tr><th>itemname</th><th>Qty</th><th>Price</th></tr>"; if (isset($_SESSION['itemname'])) { foreach($_SESSION['itemname'] as $key=>$value) { echo '<tr><td>'.$_SESSION['itemname'][$key].'</td><td>'; $_SESSION["itemqty"][$key]; echo $_SESSION["itemqty"][$key]; echo '</td><td>'.$_SESSION['itemprice'][$key].'</td><td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="value" value='.$key.'></td></tr>'; } } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928302 Share on other sites More sharing options...
TheJoey Posted October 1, 2009 Author Share Posted October 1, 2009 <html> <body> <?php if (isset($_POST['submit'])) { if($_SESSION['item']==$_POST['h1']) { $_SESSION['qty'] = $_SESSION['qty'] + 1; } else { $_SESSION['item'] = $_POST['h1']; $_SESSION['price']= $_POST['h2']; } $_SESSION['itemprice'][$_SESSION['item']] = $_SESSION['price']; $_SESSION['itemqty'][$_SESSION['item']] = $_SESSION['qty']; $_SESSION['itemname'][$_SESSION['item']] = $_SESSION['item']; } ?> <table> <tr> <td> </td> <td>ITEM info here</td></tr> <tr><td><form action="cartpost.php" method="post"><input type="submit" name="submit" value="ADDING"/><input type="hidden" name="value" value="itemid" /><input type="hidden" name="value1" value="7000"/></form> </td></tr> </table> <a href="cart.php">View your cart</a> </body> </html> this just outputs into the minicart <?php echo "The shopping cart looks as follows:--"; if(isset($_POST['submit'])) { $itemname = $_POST['value']; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='1'>"; echo "<tr><th>itemname</th><th>Qty</th><th>Price</th></tr>"; if (isset($_SESSION['itemname'])) { foreach($_SESSION['itemname'] as $key=>$value) { echo '<tr><td>'.$_SESSION['itemname'][$key].'</td><td>'; $_SESSION["itemqty"][$key]; echo $_SESSION["itemqty"][$key]; echo '</td><td>'.$_SESSION['itemprice'][$key].'</td><td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="value" value='.$key.'></td></tr>'; } } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176129-setting-default-value/#findComment-928416 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.