help with oop concept

Discussion in 'PHP' started by robg, Jan 6, 2008.

  1. #1
    Hi, just started to try and get my head round oop and am getting a bit confused. Have set up a display method which is basically a template for all my html and menus. The display method, in turn, makes a call to DisplayLeftContent(). DisplayLeftContent() outputs a sub menu, some html etc and also $this->leftcontentforpage if it has been set. This works fine until I tried to set the left content using another method from another class.

    So i have my basic layout working and decide that i want to set the leftcontent to display a table of any new orders that have come in. (see class order below). So i created a GetAllOrders() method below to pull the info from the database and used it in my script to set the left content. Now the method does its job and outputs the data, but it does not add it to the corrrect position on the page. It just ouputs the data at the top of the page, before all the other html, and pushes the rest of the site down. Now if i return the data instead of echoing it inserts into the right place but only returns the first row of the table. I'm guessing it's something to do with assinging multiple echo statments to the $leftcontentforpage attribute. Hope someone can set me on the right path on this one?

    When i want to

    My page script
    <?php
        session_start();
        require('lib/class_lib.php');
        
        $neworders = new order();
        
        $page = new page('Orders');
        $page->leftcontentforpage = $neworders->GetAllOrders(3);
        $page->Display();    
    ?>
    
    Code (markup):
    I have only left in the relevant code to the problem.

    My Class library

    class page
    {
    
    	var $leftcontentforpage;
    
    	public function DisplayLeftContent()
            {
                echo '<div id="leftnav">';
                echo '<img src="images/'.$this->currentpage.'header.jpg">';
                $this->DisplaySubMenu();
                echo "$this->leftcontentforpage"; 
                echo '</div>';
            }
    
    	public function DisplayLeftContent()
            {
                echo '<div id="leftnav">';
                echo '<img src="images/'.$this->currentpage.'header.jpg">';
                $this->DisplaySubMenu();
                echo "$this->leftcontentforpage"; 
                echo '</div>';
            }
    }
    
    class order
    {
            var $orderstatus;       
            
            public function GetAllOrders($orderstatus)
            {
                $this->orderstatus = $orderstatus;
                
                $dbh = new PDO('mysql:host=111.111.111.111;dbname=mydbname', username, password);
                $sql = "SELECT id, surname, deliverydate FROM buyer, orders WHERE id=buyerid AND orderstatus=$this->orderstatus";
                
                foreach($dbh->query($sql) as $row)
                {
                    $id = $row['id'];
              		$surname = $row['surname'];
              		$deliverydate = $row['deliverydate'];
              		$orderstatus = $row['orderstatus'];
              		
              		echo "<tr><td>$id</td><td>$surname</td><td>$deliverydate</td><td><a href='exploreorder.php?orderid=$id'><img src='images/anyclues.png'/></a></td></tr>";
              		
                }
    	                
            }
    }
    
    Code (markup):

     
    robg, Jan 6, 2008 IP