need help variable undefined |
[eluser]phpfresher[/eluser]
ERROR: undefined varible:module_id Controller: $data['list_of_module'] = $this->userprofile->list_of_module(); Model: //returns all module name and id from module table function list_of_module(){ $query = $this->db->query("select * from module "); foreach ($query->result() as $row): $module_id .= $row->id; $module_id .= ","; $module_name .= $row->name; $module_name .= ","; echo $module_name; endforeach; $comma=",";//separate by commas $module_id = rtrim($module_id,","); $module_name = rtrim($module_name,","); $arr_mod_id = explode($comma,$module_id); $arr_mode_name = explode($comma,$module_name); $options = array_combine($arr_mod_id,$arr_mode_name); $data['list_of_module'] = $options; return $data; } VIEW: <?php echo form_dropdown('category',@$list_of_module); ?> Can you help me out why the variable is undefined: the actual output is fine.
[eluser]Sudz[/eluser]
Use this code Controller: Code: $data[‘list_of_module’] = $this->userprofile->list_of_module(); Model: Code: //returns all module name and id from module table VIEW: Code: echo form_dropdown(‘category’,@$list_of_module);
[eluser]danmontgomery[/eluser]
step 1: http://ellislab.com/forums/viewthread/186906/ step 2: Code: Model: step 3: answer! The warning you see is because you're appending a value to a variable that doesn't exist: Code: $module_id .= $row->id; You can either declare the variable before the loop: Code: $module_id = ''; Or, just get rid of the whole thing as suggested.
[eluser]phpfresher[/eluser]
Thanks for your support: but it didnot work either.. my output is right but only the message arise undefined variable but the variable has value
[eluser]phpfresher[/eluser]
Thanks dude you finally did .. thanks for your support.. |
Welcome Guest, Not a member yet? Register Sign In |