i'm building a website where users can add articles. on the admin side, they can also add new fields on the add articles page.
to allow the user edit the articles, i have to query the database and then assign the results from the query to variables, usually i use the $fieldname.
the problem is, if a user added a new field while he added the article, i can't fetch the content by field anme from the rusult set of the query.
eg:

$select = $article->select();
		$select->where('id =?', $id);
		while ($rows = $article->fetchAll($select)){
			$this->cat_id = $rows->cat_id;
			$this->article_title = $rows->title;
			$this->description = $rows->description;
			:
                        :
		}

but if i dont know the name of the new field(s) the user added, i can't assign it to a variable.
PS: i was thinking of a solution that would need me to fetch the name of the fields form the article_fields table, but then again i got stuck trying to assign the field name to a variable that had the same name i.e:

$select = $article_fields->select();
			while ($rows = $article_fields->fetchAll($select)){
			${$rows->field_name}= $rows->field_name;
			;

Does anyone have any solutions??

Member Avatar for Rhyan

Your select can always be ' select * from whatever'.
Then you just retrieve an associative array using mysql_fetch_assoc, and then run a foreach loop like this

foreach( $result as $key => $value)
  {
  echo 'Field name:'.$key."\n Field value".$value;
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.