| | |
fetching unkown column names
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 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:
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:
Does anyone have any solutions??
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:
PHP Syntax (Toggle Plain Text)
$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; : : }
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:
PHP Syntax (Toggle Plain Text)
$select = $article_fields->select(); while ($rows = $article_fields->fetchAll($select)){ ${$rows->field_name}= $rows->field_name; ;
Does anyone have any solutions??
Last edited by cali_dotcom; Nov 18th, 2008 at 9:03 pm.
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
Then you just retrieve an associative array using mysql_fetch_assoc, and then run a foreach loop like this
PHP Syntax (Toggle Plain Text)
foreach( $result as $key => $value) { echo 'Field name:'.$key."\n Field value".$value; }
Last edited by Rhyan; Nov 18th, 2008 at 9:04 pm.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
![]() |
Other Threads in the PHP Forum
- Previous Thread: Page breaks for printing on php page
- Next Thread: Learning PHP...
| Thread Tools | Search this Thread |
ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu method mlm multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validator variable video web xml youtube





