[eluser]xavieremerson[/eluser]
hi..
I'm very new to codeigniter... This article is very much helped me. But I am changed the sql statements in this. Instead of that I used an array variable..
Here is the code ....
Any way thankz.... for giving idea...
function form_dropdown_from_db($name = '', $array,$data,$selected = array(), $extra = '')
{
//$CI =& get_instance();
if ( ! is_array($selected))
{
$selected = array($selected);
}
// If no selected state was submitted we will attempt to set it automatically
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
if (isset($_POST[$name]))
{
$selected = array($_POST[$name]);
}
}
if ($extra != '') $extra = ' '.$extra;
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
$att = '';
foreach ($data as $key => $val)
{
$att .= $key . '="' . $val . '" ';
}
$form = '<select name="'.$name.'"'.$extra.$multiple. $att . ">\n";
if (count($array) > 0)
{
foreach ($array as $row)
{
$values = array_values($row);
if (count($values)===2){
$key = (string) $values[0];
$val = (string) $values[1];
//$this->option($values[0], $values[1]);
}
$sel = (in_array($key, $selected))?' selected="selected"':'';
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
}
$form .= '</select>';
return $form;
}