Jump to content

Archived

This topic is now archived and is closed to further replies.

nickholt1972

Shopping Basket - changing quantities & removing items problem

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.

Share this post


Link to post
Share on other sites
That is really weird the code looks good to me, can we see the database information please.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.