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

pobster’s picture

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

newtodrupal’s picture

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

anupom.gogoi’s picture

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,
);

newtodrupal’s picture

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

anupom.gogoi’s picture

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'];
}

newtodrupal’s picture

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