...

View Full Version : Shopping Cart



Pee-H-Pee
01-24-2004, 11:59 AM
Hello,

I am trying to make my own shopping cart and everything is working good. Adding products, removing, editing, etc... Only thing is I need to number some of the values starting from one and then on... but I can't figure out how to number the items...

For example, assuming there are 3 products in the shopping cart then it would look like:



// Get contents of users shopping cart and show customer

$result = mysql_query("select * from cart WHERE id='$cart_id'") or die (mysql_error());
while ($row = mysql_fetch_array($result))
{

echo "

<input type=hidden name=item1 value=$row[pid]><input type=hidden name=quantity1 value=$row[quantity]>

<input type=hidden name=item2 value=$row[pid]><input type=hidden name=quantity2 value=$row[quantity]>

<input type=hidden name=item3 value=$row[pid]><input type=hidden name=quantity3 value=$row[quantity]>

";

}

mysql_free_result($result);


Thank You :o

gammahelixx
01-24-2004, 12:47 PM
I'm not 100% sure I follow you why you need multiple hidden vars with the cart's contents, but here's a possible solution:



$i = 1;
while ($row = mysql_fetch_array($result))
{
echo "<input type=hidden name=item$i value=$row[pid]><input type=hidden name=quantity$i value=$row[quantity]>";
$i++;
}


This may do the trick. Each row in the array would iterate this echo statement and increment $i one each time.

Hope this helps!

Pee-H-Pee
01-24-2004, 05:53 PM
Thanks for the reply...
That kind of works...
When I add one item to the cart it shows up in the source code but the hidden fields do not. But if I add another item to the shopping cart the hiddend fields for the first added items shows up, and if I add a third item that does not show up either for the hidden fields. So for some reason only one item (row) is being displayed for the hidden fields.

Example:
(PID - Quant.)

911 - 2<BR>

740 - 1<BR>

333 - 1<BR>

<form method="post" action="http://www.URL.com">
<input type=hidden name=action value=buy>
<input type=hidden name=itemcount value=3>
<input type=hidden name=item1 value=740><input type=hidden name=quantity1 value=1><input type=hidden name=item2 value=333><input type=hidden name=quantity2 value=1>
<P><input type=submit value="Checkout">
</form>

Here is the viewcart script that I have so far:



// Get contents of users shopping cart and show them

$result = mysql_query("select * from cart WHERE id='$cart_id'") or die (mysql_error());
while ($row = mysql_fetch_array($result))
{

$i = 1;
while ($row = mysql_fetch_array($result)){
echo "<input type=hidden name=item$i value=$row[pid]><input type=hidden name=quantity$i value=$row[quantity]>";
$i++;
}

}

mysql_free_result($result);


Thank You :o

Pee-H-Pee
01-24-2004, 06:01 PM
oh, looks like it does add the third one...
for some reason the very first one is not showing up though...

Pee-H-Pee
01-24-2004, 06:16 PM
Doh!
I need a cup of coffee! :D

Guess it helps to only have one "while" in there...
I got it to work.

Thanks again for the help!



$result = mysql_query("select * from cart WHERE id='$cart_id'") or die (mysql_error());
$i = 1;
while ($row = mysql_fetch_array($result)){
echo "<input type=hidden name=item$i value=$row[pid]><input type=hidden name=quantity$i value=$row[quantity]>";
$i++;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum