0

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??

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Rhyan
0

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;
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.