View Full Version : More Classes Help

07-24-2007, 08:20 PM
class User{

var $username2;
var $activepet;
var $query;
var $spare;

function User() {
$this->query=mysql_query("SELECT * FROM `Member` WHERE `loginName` = '$this->username2'") or die("Error with User Function" . mysql_error());
$username2 = $this->spare['loginName'];
$activepet = $this->spare['activepet'];
return $username2;
return $activepet;

So this is my class, and what happens is this:

$details = new User;
$username = ($_SESSION['username']);

I was wondering how i get both $username2 and $activepet results back? Simple echoing the vairables doesn't work =/

07-24-2007, 10:01 PM
You should create functions (sometimes referred to as getters) to get values back from within a class.

try the adding the following functions inside your class

function getUserName() {
return $this->username2;
function getActivePet() {
return $this->activepet;

Once you have done that, try and print the values like so

echo "User Name: " . $details ->getUserName();
echo "<br/>Active pet: " . $details ->getActivePet();

I would recommend that you look at the OOP tutorial from php.net. here is the url http://www.php.net/oop