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 3 of 3
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Post Any help on this wfCart system would be great

    Any help on this wfCart system would be great.

    I am lost at the basics; can't seem to get the idea to work.
    I know if I do select * from table the result would be an array()

    How to get the db values to work ?
    Do I just call them with;
    $rsproducts[fld-value] ?
    PHP Code:
    <?php 
    require_once('conndb.php'); 
     
    mysql_select_db($database_cngal$cngal);
    $query_rsproducts "SELECT * FROM main_image ORDER BY id ASC  limit 6";
    $rsproducts mysql_query($query_rsproducts$cngal) or die(mysql_error());
    $row_rsproducts mysql_fetch_assoc($rsproducts);
    $totalRows_rsproducts mysql_num_rows($rsproducts);
    // You must included wfcart.php BEFORE you start the session. 
    include "wfcart.php";
    session_start();      // start the session
    $cart =& $_SESSION['wfcart']; // point $cart to session cart.
    if(!is_object($cart)) $cart = new wfCart(); // if $cart ( $_SESSION['cart'] ) isn't an object, make a new cart
    // end of header stuff
    ?>
    <html>
    <head>
    <title>wfCart Demo</title>
    </head>
    <body><h3>wfCart Demo</h3>
    <?

    //Start of my idea
    $products = array();
    do {
    $products[] = array("id"=>$row_rsproducts['id'],"name"=>$row_rsproducts['name'],"price"=>$row_rsproducts['price']);
    } while (
    $row_rsproducts mysql_fetch_assoc($rsproducts));
    //end of my idea

    /*Usually you would get your products from a database but we'll pretend..  
    $products = array();
    $products[1] = array("id"=>1,"name"=>"A Bar of Soap","price"=>2.00);
    $products[2] = array("id"=>2,"name"=>"Shampoo","price"=>4.80);
    $products[3] = array("id"=>3,"name"=>"Pizza","price"=>12.95);
    */
    // check to see if any items are being added
    if($_POST['add']) {
     
    $product $products[$_POST['id']];
     
    $cart->add_item($product['id'],$_POST['qty'],$product['price'],$product['name']);
    }
    if(
    $_POST['remove']) {
     
    $rid intval($_POST['id']);
     
    $cart->del_item($rid);
    }
    // spit some forms
    // You can have many different types of forms, such as many quantity boxes
    // and an "add to cart" button at the bottom which adds all items
    // but for the purposes of this demo we will handle one item at a time. 
    echo "<table>";
    foreach(
    $products as $p) {
     echo 
    "<tr><td><form method='post' action='demo.php'>";
     echo 
    "<input type='hidden' name='id' value='".$p['id']."'/>";
     echo 
    "".$p['name'].' R'.number_format($p['price'],2)." ";
     echo 
    "<input type='text' name='qty' size='5' value='1'><input type='submit' value='Add to cart' name='add'>";
     echo 
    "</form></td></tr>";
    }
    echo 
    "</table>";
    echo 
    "<h2>Items in cart</h2>";
    if(
    $cart->itemcount 0) {
     foreach(
    $cart->get_contents() as $item) {
      echo 
    "<br />Item:<br/>";
      echo 
    "Code/ID :".$item['id']."<br/>";
      echo 
    "Quantity:".$item['qty']."<br/>";
      echo 
    "Price   :R".number_format($item['price'],2)."<br/>";
      echo 
    "Info    :".$item['info']."<br />";
      echo 
    "Subtotal :R".number_format($item['subtotal'],2)."<br />";
      echo 
    "<form method=post><input type='hidden' name='id' value='".$item['id']."'/>
      <input type='submit' name='remove' value='Remove'/>
      <input type='button' name='Print' value='Print' onclick='javascript:window.print()'/> // added this in
    </form>"
    ;
    }
     echo 
    "---------------------<br>";
     echo 
    "total: R".number_format($cart->total,2);
    } else {
     echo 
    "No items in cart";
    }
    ?>
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    yeah you shud just access the db values by doing...
    PHP Code:
    $value $row_rsproducts['fieldname']; 
    these have to be in a loop like in ur code above.

    is this dreamweaver code?

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Cool Here is my first PHP cart!

    Here is my first PHP cart!

    Be kind it's my FIRST in PHP and it's far from complete

    Just to let some know that I am serious about this PHP cart thingy.
    This is seriously, seriously, seriously and etc... only a DEMO!

    my first PHP cart

    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

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