nickholt1972 Posted October 8, 2006 Share Posted October 8, 2006 I've set up a shopping basket. It works in so much as I can add items from my product pages to the basket and it lists them with their prices. Trouble is, now i need to be able to let shoppers alter quantities from the default (1), I also need to let them remove items.I've experimented with a text box or drop down list but if I send the quantity as a $_POST variable, it changes the quantity on all the items in the basket.This is the code which displays the items in the basket. You may note, i've hardcoded the default quantity (1) whilst i work out what to do.[code] $total = 0; for ($i = 0; $i < count($_SESSION['basket']); $i++) {$alldetails = @mysql_query('SELECT * FROM stocks WHERE id = ' . $_SESSION['basket'][$i]);while ($row = mysql_fetch_array($alldetails)) { echo '<tr>'; echo '<td>' . $_SESSION['basket'][$i] . '</td>'; // id echo '<td>' . $row['alphaname'] . '</td>'; // product name$quantity = 1; echo '<td>' . $quantity . '</td>'; // quantity$subtotal = $row['price'] * $quantity; echo '<td align="right">£' . number_format($subtotal, 2) . '</td>'; // price echo '<td>remove</td>'; echo '</tr>'; $total = $total + $subtotal; }}[/code]Any suggestions would be greatly appreciated. Also the issue of removing items I don't esxpect to be too hard but still some assistance would be really helpful.Thanks,Nick. Link to comment https://forums.phpfreaks.com/topic/23353-shopping-basket-changing-quantities-removing-items-problem/ Share on other sites More sharing options...
redarrow Posted October 8, 2006 Share Posted October 8, 2006 That is really weird the code looks good to me, can we see the database information please. Link to comment https://forums.phpfreaks.com/topic/23353-shopping-basket-changing-quantities-removing-items-problem/#findComment-105854 Share on other sites More sharing options...
nickholt1972 Posted October 8, 2006 Author Share Posted October 8, 2006 Oh yes the code works as it is, but it doesn't let users [i]change[/i] the quantities in the basket. Currently it would just display id, productname, quantity and price but the quantity would be 1 by default because of the [b]$quantity = 1[/b] variable.I want to add the functionality so a user can decide to order 2 or 12 or whatever, and i don't know how to go about it.Thanks,Nick. Link to comment https://forums.phpfreaks.com/topic/23353-shopping-basket-changing-quantities-removing-items-problem/#findComment-105872 Share on other sites More sharing options...
redarrow Posted October 8, 2006 Share Posted October 8, 2006 Might be the logic of your thorts usally a user can specify how meny they want from the order page then you deduct that amount form the user product that sold the product when paid for. Link to comment https://forums.phpfreaks.com/topic/23353-shopping-basket-changing-quantities-removing-items-problem/#findComment-105875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.