Why isn't this working??
Posted: Thu Oct 13, 2005 11:21 am
Hey team,
I've tried this a number of different ways but can't get it to work..
Class Code..
Calling the class..
All that is printing out is a comma.. seems like the vars aren't getting to the getName() function.. is this a scope problem? I've found code all over the web that looks just like this.. am I overlooking something?
Thanks
Will
I've tried this a number of different ways but can't get it to work..
Class Code..
Code: Select all
class User {
var $chNameFirst; //tried it with and without this..
function User($id = NULL) {
$dbConnect = mysql_connect(DBHOST, DBUSER, DBPASS) or die ("Could not connect to Database Server.");
mysql_select_db(DB) or die("Could not connect to Database.");
if($id != NULL) {
$sql = "SELECT * FROM tblUsers WHERE userID = $id";
$set = mysql_query($sql) or die("Error getting user Info in class instantiation: ".mysql_error());
$row = mysql_fetch_object($set);
$this->chNameFirst = $row->chNameFirst;
$this->chNameLast = $row->chNameLast;
}
function getName($how) {
switch($how) {
case "lf":
$ret = $this->chNameLast.", ".$this->chNameFirst;
break;
case "fl":
$ret = $this->chNameFirst." ".$this->chNameLast;
break;
}
return $ret;
}
}Code: Select all
$user = new User($_SESSION['id']);
print getName("lf");Thanks
Will