Re: Calling methods from others classes

From: Date: Sun, 21 Sep 2008 14:59:55 +0000
Subject: Re: Calling methods from others classes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-280638@lists.php.net to get a copy of this message
Ben Stones wrote:
Hi, I have this piece of code that I have created: class userQueries {
    public function numberUsers() {
        $get_users=mysql_query("SELECT * FROM users WHERE online <
NOW()") or exit("../includes/error.php");
    }
} class usersOnline extends userQueries {
    public function usersOnline() {
        echo mysql_num_rows($this->numberUsers);
    }
} How do I request specific methods in other classes? The error that comes up is: mysql_num_rows(): supplied argument is not a valid MySQL result resource which is somewhat expected as $this only refers to the variables and there are no variables called numberUsers.
You forgot to "return $get_users;" from your numberUsers() function.... Also in your code you will never free the result nicely which is bad. In order to count the users, you should possibly also use SELECT COUNT(*) FROM... and then use the single value that is returned as this will be more efficient (does not require all the data to be fetched and sent). Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/]

« previous php.general (#280638) next »