Question on using and assigning an array within a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kgray
Forum Newbie
Posts: 4
Joined: Sat Nov 27, 2004 11:53 am

Question on using and assigning an array within a class

Post by kgray »

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.

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);*/
                }
}
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
Post Reply