Jump to content

Shopping Basket - changing quantities & removing items problem


nickholt1972

Recommended Posts

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
Share on other sites

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
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.