By aries30_mel on
I'm currently working on my module and I don't know how to retrieve data from the database so I can use them as options on my select box..
I need immediate response on this matter. Hope I can get one from you guys....
Thanx...........
---meLai---
Comments
How you do it will depend on
How you do it will depend on how you've coded already and what you're trying to achieve? (You a little too vague?) I can either point you at some example modules or you can post some code to show what you're trying to do that doesn't work...
Pobster
Similar issue
I have also come across a similar issue
basically i have a form element
$form['drop'] = array(
'#type' => 'select',
now how can i add '#options' = array( to include the values obtained from database
You just need to create
You just need to create $option array by using db_query.
For example:
$sql = db_query("Select * From {node} Where type = '%s'", 'page');
while($o = db_fetch_array($sql)) {
$options[] = $o['title'];
}
$form["drop"] = array(
'#type' => 'select',
'#title' => t('My Select Box'),
'#options' => $options,
);
My Blog site: http://www.anupomgogoi.com
thank you
thank you. So, if it was our normal drop down, it would be '1' => t('description') so in the above code how will the value be given to the title like can i give a structure like
id of the row -> description
For such condition, you can
For such condition, you can create the $option array this way:
$sql = db_query("Select * From {node} Where type = '%s'", 'page');
while($o = db_fetch_array($sql)) {
$options[$o['nid']] = $o['title'];
}
My Blog site: http://www.anupomgogoi.com
Thank you again.
Thank you again so much. It works perfectly. Could you please help me in this or point me in the right direction. I am pretty much new to drupal and have only just started it. The javascript part is really killing me
http://drupal.org/node/466848