0

I am newbie to php I need help I want to add where clause to this 'get_select_option'

my get_select_option code is here

function get_select_option($table,$id,$name,$selected=0){
  $query = $this->db->get($table);
  $select = '<option value="">SELECT</option>';
  if($query->num_rows()>0){
   foreach($query->result_array() as $row){
   $selected_option = ($selected==$row[$id]) ? ' selected="selected" ':' ';
    $select.='<option value="'.$row[$id].'" '. $selected_option.'>'.trim(strtoupper($row[$name])).'</option>';
   }
  }
  return $select;
 }
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36
anonymous
  • 67
  • 1
  • 7

2 Answers2

1

In Codeigniter you can set the where clause by using $this->db->where();. The code will be -

$this->db->where('fieldname', 'valuetomatch');
$query = $this->db->get($table);
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

Use this line $this->db->where('column_name','your_value'); in the below function above your $query = $this->db->get($table); statement

function get_select_option($table,$id,$name,$selected=0){
            $this->db->where('column_name','your_value');
            $query = $this->db->get($table);
            $select = '<option value="">SELECT</option>';
            if($query->num_rows()>0){
                foreach($query->result_array() as $row){
                $selected_option = ($selected==$row[$id]) ? ' selected="selected" ':' ';
                    $select.='<option value="'.$row[$id].'" '. $selected_option.'>'.trim(strtoupper($row[$name])).'</option>';
                }
            }
            return $select;
        } 
Abhinav
  • 8,028
  • 12
  • 48
  • 89