Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Senior Member Richard S's Avatar
    Join Date
    Jul 2004
    Location
    SW Lonodn
    Posts
    219
    Member #
    6728
    Liked
    3 times
    Hi all,

    I'm currently trying to get my head round the concepts of OOP.

    I manged to get a class working last night. It's a shopping cart Class that allows you to add, delete itmes and display the basket on your web page.

    It works fine and is deffinetly useful and reuseable.

    But I'm not sure if I've realy got the fundermentle princibles of OOP right.

    I'm hoping someone here could look at what I've done and comment/ suggest better ways of going about it.

    This is a outline of my class:

    PHP Code:
    <?php
    class basket
    {
        var 
    $basket//cust number
        
    var $lbg_col//light background colour
        
    var $dbg_col//dark background colour
        
    var $width//width of the table
        
    var $bg_col //colour of the main background
        
    function basket ()
            
    /*This is the constuctor - In this case we need to check that there is a unique
            customer ID cookie stored on the client computer. If it's not there we set it.
            Then it gets asigned to the $this->basket variable of this instance */
            
    {
            
    $this->lbg_col '#F2F2F0';//set defualts for vars, if net set from the outside
            
    $this->dbg_col '#FDFFF0';
            
    $this->bg_col '#CCCCCC';
            

                if (!isset(
    $_COOKIE['cust_no']))
        
                                  {
                        
    $week =(36000 24) * 7;

                            
    mysql_connect ("localhost""*****""********") or die ('I cannot connect to the database because: ' mysql_error());
                            
    mysql_select_db ("richard_coopershop");
                            
    $no_cust_sql "SELECT * FROM customers";
                            
    $result=mysql_query($no_cust_sql);
                            
    $rows mysql_numrows($result);
                            
    $value $rows 1;
            
                            
    $sql "INSERT INTO `customers` ( `index` , `date` ) 
                            VALUES ( 
    $value , CURDATE( ) )";
                            
    mysql_query($sql);
            
                            
    setcookie("cust_no"$valuetime()+$week"/cooper3/"".rrss.co.uk") or die("Could not set cookie");
                            echo 
    "This is your first visit here today.";
                            
    mysql_close();
                    }
                    
                    
    $this->basket $_COOKIE['cust_no'];
            }

        function 
    del_item($item_no)
            
    /*This method is used to delete a row from the shopping basket. The item number
            comes from the outside and is a unique index in the basket table.*/
            
    {

            
            }
        function 
    add_item($add,$amount,$colour)
            
    /*This function adds a item from the store in to the shopping basket.
            The varables $add, $amount and $colour are passed from the out side.
            The $cust_no is attached to this instance
            */
            
    {

                     }
        function 
    display_basket()
            
    /*This method displays the contents of the customers basket in their browser
                It simply looks at $this->basket and echos out each row formated with a table.
                Fianly it works out a total cost at the end.*/
            
    {
                    
    /* Pull out all the rows in the basket table using the $this->basket var then build display the HTML table with the other vars*/

                    
    }
    }

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:25 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com