View Single Post
Old 06-07-2009, 01:43 PM   #7 (permalink)
captainmerton
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Apologies still cant get this to work. Any advice? I am now getting the message "Fatal error: Using $this when not in object context" when i use $this->username

Here's the onject instantiation client code:

PHP Code:
OnlineNowTable::writeTable($_SESSION['name']); 
Here's the class code:

PHP Code:
    abstract class TableWriter {
        public 
$username;

        
/* Constructor */
        
public function __construct($username) { 
            
$this->username    $username;
        }
        
        abstract public function 
writeTable();
    }
    
    class 
OnlineNowTable extends TableWriter {

        public function 
writeTable() {

            
$query "select username from login where (loggedin > 0) AND (username != '$this->username')";

            
$result mysql_query($query) OR die('Cannot perform OnlineNowTable query!');

            
$str "<table><tr><th>Online Now</th></tr>";

            if (
mysql_num_rows($result) == 0) {        
                
$str .= "<tr><td>nobody online</td></tr>";
            }
            else {
                while(
$row mysql_fetch_array($result))
                {
                
$str .= '<tr><td>'.$row['username'].'</tr></td>';
                }
            }

            
$str .= "</table>";
            
            print 
$str;
        
        }
    } 
captainmerton is offline  
Reply With Quote