Welcome Guest, Not a member yet? Register   Sign In
need help variable undefined
#1

[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.
#2

[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
  function list_of_module(){
            $this->db->select();
           $query =  $this->db->get(`module`)->result();

            foreach ($query as $row):
              
           $data[$row->id] = $row->name;
            
             endforeach;
        
          return $data;
  }

VIEW:

Code:
echo form_dropdown(‘category’,@$list_of_module);
#3

[eluser]danmontgomery[/eluser]
step 1: http://ellislab.com/forums/viewthread/186906/

step 2:
Code:
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;
  }

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 = '';
$module_name = '';

Or, just get rid of the whole thing as suggested.
#4

[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
#5

[eluser]phpfresher[/eluser]
Thanks dude you finally did .. thanks for your support..




Theme © iAndrew 2016 - Forum software by © MyBB