Jump to content

OOP class assigning issue


strazdinjsh

Recommended Posts

would anyone know how to assign the value (value returned by some function in the class) of variable $temp in the class: source looks like:

 

class newRecord{
var $temp = listCat('gallery_menu', 'submenu', 'submenu_id'); ////// this line is not working, does not assign?

	function listCat($table, $submenu, $submenu_id)
	{
	$return = '<select name="'.$submenu_id.'" id="'.$submenu_id.'">';
	$result = mysql_query("SELECT * FROM $table");
	while($row=mysql_fetch_object($result))
		{
		$return = $return.'<option value="'.$row->id.'">'.$row->$submenu.'</option>';
		}
		$return = $return.'</select>';
	return $return;
	}


}

 

if function is used out of the class and used in index.php directly, returns expected value of it (there is no doubts - works ok)

Link to comment
Share on other sites

You need to put it within the classes constructor.

 

class newRecord
{
  private $temp = array();

  public function __construct()
  {
    $this->temp = $this->listCat('gallery_menu', 'submenu', 'submenu_id');
  }

  // rest of code.
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.