Question on using and assigning an array within a class
Posted: Tue Nov 30, 2004 11:53 am
Hi,
When you look at the very stipped down code below, it will be obvious that I am new to PHP. Error checking and such has been removed.
My question is using an array as a class member.
Everything works if initialize a function variable and pass it to the calling function. I am just trying to understand why the array is not being filled or changed within the class function.
I hope I am being clear enough, for my brain is starting to turn into mush. BTW, this PHP BBCode is great.
Thanks in advance,
Ken
When you look at the very stipped down code below, it will be obvious that I am new to PHP. Error checking and such has been removed.
My question is using an array as a class member.
Code: Select all
class connection
{
var $row;
#have tried initializing array with var $row = array('id' => " ",....)
function get_record($sql)
{
/*Have assigned values to variables in $this->row, which print out but cannot be changed in this function.
unset($this->row) does not clear array? */
$result=@mysql_query($sql);
#Have tried $this->row=array(mysql_fetch_assoc($result));
$this->row = mysql_fetch_assoc($result); #does not work
/* works
$row = mysql_fetch_assoc($result);
return $row
does not work
$this->row = $row;
or this
$this->row = array($row);*/
}
}I hope I am being clear enough, for my brain is starting to turn into mush. BTW, this PHP BBCode is great.
Thanks in advance,
Ken