Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Shopping Cart

  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shopping Cart

    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:

    PHP Code:
    // 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

  • #2
    New to the CF scene
    Join Date
    Jan 2004
    Location
    Florence, AL
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    $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!

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    // 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

  • #4
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, looks like it does add the third one...
    for some reason the very first one is not showing up though...

  • #5
    New Coder
    Join Date
    Jan 2004
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh!
    I need a cup of coffee!

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

    Thanks again for the help!

    PHP Code:
    $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++;



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •