Jump to content

Korken

Member
  • Posts

    10
  • Joined

  • Last visited

Posts posted by Korken

  1. Hmm, something like this should probably work:

     

    >function render_products_from_xml()
    {
       $output = "</pre>
    <table>
    
    $product->title
    
    
                       $product->description
    
    
                       ?$product->price
    
    
    add to cart
    
    
    </table>";<br><br>   return $output

  2. Add a counter, and when you reach 3 print "

    Hope it helps!

     

    //Emil

     

    Edit: Example, somthing like this:

    $i = 0;
    echo "";
    foreach (get_shopping_cart() as $prod)
    {
       echo "$prod";
    
       if ($i >= 2)
       {
           echo "";
           $i = 0;
       }
       else
           i++;
    }
    echo "";

  3. Is this what you wanted? Then will each one beome it's own row in the database.

    Hope it helps.

     

    foreach($_POST['Activity'] as $row=>$Act)
    {
       $Activity = mysql_real_escape_string($Act); 
       $Position = mysql_real_escape_string($_POST['Position'][$row]);
       $StartDate = mysql_real_escape_string($_POST['StartDate'][$row]);
       $EndDate = mysql_real_escape_string($_POST['EndDate'][$row]);
    
       $involv = "INSERT INTO Involvement(Activity, Position, StartDate, EndDate)
                  VALUES('$Activity', '$Position', '$StartDate', '$EndDate')";
    
       mysql_query($involv);
    }
    
    

  4. This may help :)

    I just watched the free movies and then worked on the rest by my self.

     

    <?php
    /**********************************************************************
    * - Made in the Eclipse IDE: www.eclipse.org
    * - Tested on PHP 5.2
    * - Kickstart in OOPHP: www.killerphp.com
    * 
    * Usage of the class ShoppingCart
    * 
    * Attention!: product_id is a string and value is an integer.
    * 
    * -> addItem("product_id"):
    * This will add an item to the cart.
    * If the item already exists, the quantity of that item will increased by 1.
    * 
    * -> deleteItem("product_id"):
    * This will remove an item from the cart.
    * Remove as in it will be gone, if you want to change the quantity see 'SetQuantity'.
    * 
    * -> getItems():
    * This will return an array with all the items in the cart.
    * 
    * -> setQuantity("product_id", value):
    * This will change the quantity of the item to value.
    * If value is 0 the item will be automatically removed.
    * 
    * -> getQuantity("product_id"):
    * This will return the quantity of the item.
    * 
    * 
    * Design of the cart array:
    *  _______________________
    * | Product ID | Quantity |
    * |  (string)  |  (int)   |
    * |------------|----------|
    * | exampleid1 |    5     |
    * |- - - - - - | - - - - -|
    * | exampleid2 |    3     |
    * |- - - - - - | - - - - -|
    * | exampleid5 |    13    |
    *  -----------------------
    **********************************************************************/
    
    class ShoppingCart
    {
       private $cart = array();
    
       public function addItem($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               $this->cart[$product_id] += 1;
           else
               $this->cart[$product_id] = 1;
       }
    
       public function deleteItem($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               unset($this->cart[$product_id]);
       }
    
       public function getItems()
       {
           return array_keys($this->cart);
       }
    
       public function setQuantity($product_id, $value)
       {
           if (array_key_exists($product_id, $this->cart))
           {
               if ((int)$value > 0)
                   $this->cart[$product_id] = (int)$value;
               else
                   unset($this->cart[$product_id]);
           }
       }
    
       public function getQuantity($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               return $this->cart[$product_id];
       }
    }
    ?>

  5. Hmm, it sems the array is a bit wrong;

    $prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00", );

     

    Should be (notice the last ", " i removed):

    $prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00");

     

     

    //Emil Fresk

    Sweden

  6. Edit: Changed the code a bit.

     

    Hello!

     

    This is my 2nd post here (Sorry for the wrong forum with the first one! :| ) and my first try at OOPHP.

    I watched the beginner videos, looked at the first three (free) movies of the shopping cart tutorial and decided to finnish it without any more help to see how it became.

    So after a few hours I ended up with this:

    Please comment if I should have done anything in a different way or if it looks okey. :)

     

    Thanks for the tutorials KillerPHP!

     

    //Emil Fresk

    Sweden

     

     

    Code:

    <?php
    /**********************************************************************
    * - Made in the Eclipse IDE: www.eclipse.org
    * - Tested on PHP 5.2.
    * - Kickstart in OOPHP: www.killerphp.com
    * 
    * Usage of the class ShoppingCart
    * 
    * Attention!: product_id is a string and value is an integer.
    * 
    * -> AddItem("product_id"):
    * This will add an item to the cart.
    * If the item already exists, the quantity of that item will increased by 1.
    * 
    * -> DeleteItem("product_id"):
    * This will remove an item from the cart.
    * Remove as in it will be gone, if you want to change the quantity see 'SetQuantity'.
    * 
    * -> GetItems():
    * This will return an array with all the items in the cart.
    * 
    * -> SetQuantity("product_id", value):
    * This will change the quantity of the item to value.
    * If value is 0 the item will be automatically removed.
    * 
    * -> GetQuantity("product_id"):
    * This will return the quantity of the item.
    * 
    * 
    * Design of the cart array:
    *  _______________________
    * | Product ID | Quantity |
    * |  (string)  |  (int)   |
    * |------------|----------|
    * | exampleid1 |    5     |
    * |- - - - - - | - - - - -|
    * | exampleid2 |    3     |
    * |- - - - - - | - - - - -|
    * | exampleid5 |    13    |
    *  -----------------------
    **********************************************************************/
    
    class ShoppingCart
    {
       private $cart = array();
    
       public function AddItem($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               $this->cart[$product_id] += 1;
           else
               $this->cart[$product_id] = 1;
       }
    
       public function DeleteItem($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               unset($this->cart[$product_id]);
       }
    
       public function GetItems()
       {
           return array_keys($this->cart);
       }
    
       public function SetQuantity($product_id, $value)
       {
           if (array_key_exists($product_id, $this->cart))
           {
               if ((int)$value > 0)
                   $this->cart[$product_id] = (int)$value;
               else
                   unset($this->cart[$product_id]);
           }
       }
    
       public function GetQuantity($product_id)
       {
           if (array_key_exists($product_id, $this->cart))
               return $this->cart[$product_id];
       }
    }

×
×
  • Create New...