Welcome Guest, Not a member yet? Register   Sign In
Form dropdown from db data
#6

[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;
}


Messages In This Thread
Form dropdown from db data - by El Forum - 11-15-2008, 11:46 AM
Form dropdown from db data - by El Forum - 11-15-2008, 08:09 PM
Form dropdown from db data - by El Forum - 11-17-2008, 09:21 AM
Form dropdown from db data - by El Forum - 11-17-2008, 10:37 AM
Form dropdown from db data - by El Forum - 03-30-2009, 07:44 PM
Form dropdown from db data - by El Forum - 12-02-2010, 01:57 AM
Form dropdown from db data - by El Forum - 12-12-2010, 04:40 PM
Form dropdown from db data - by El Forum - 01-16-2011, 10:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB