| | |
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 |
Tag cloud for PHP
.htaccess access ajax apache api array basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete development directory display download dynamic echo email error file files folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms soap source space sql structure syntax system table trouble tutorial update upload url validation validator variable video web xml youtube





