954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

fetching unkown column names

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

cali_dotcom
Junior Poster in Training
53 posts since Apr 2008
Reputation Points: 10
Solved Threads: 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;
  }
Rhyan
Posting Whiz in Training
240 posts since Oct 2006
Reputation Points: 21
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You