Jump to content


Photo

Shopping Basket - changing quantities & removing items problem


  • Please log in to reply
3 replies to this topic

#1 nickholt1972

nickholt1972
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationBury, Lancs, UK

Posted 08 October 2006 - 01:59 PM

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.

$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;
  }}

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.
Nick Holt - Future Guru

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 October 2006 - 02:29 PM

That is really weird the code looks good to me, can we see the database information please.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 nickholt1972

nickholt1972
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationBury, Lancs, UK

Posted 08 October 2006 - 03:02 PM

Oh yes the code works as it is, but it doesn't let users change 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 $quantity = 1 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.

Nick Holt - Future Guru

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 October 2006 - 03:10 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users