I want to retrieve some data which role is the ‘admin’,’superadmin’,’employee’ but it selected only the admin data. I am trying with this code.
<?php
$users=$this->db->select(‘*’)->from(‘users’)->where(‘role’,’admin’)->->where(‘role’,’superadmin’)->where(‘role’,’employee’)->get()->result_array();
print_r($users);
?>
How to retrieve enumerated field values from MySQL table using PHP codeigniter.
Follow this code and apply it in your code:
<?php
$enums = $this->field_enums(‘users’, ‘role’);
$usersData=array();
foreach ($enums as $key => $value) {
$users=$this->db->select(‘*’)->from(‘tablename’)->where(‘role’,$value)->get()->result_array();
if(sizeof($users)>0){
foreach ($users as $u_value) {
array_push($usersData,$u_value);
}
}
}
Create enums function in your controller
public function field_enums($table = ”, $field = ”){
$enums = array(‘admin’,’superadmin’,’employee’);
if ($table == ” || $field == ”) return $enums;
$CI =& get_instance();
preg_match_all(“/'(.*?)’/”, $CI->db->query(“SHOW COLUMNS FROM {$table} LIKE ‘{$field}'”)->row()->Type, $matches);
foreach ($matches[1] as $key => $value) {
//$enums[$value] = $value;
return $enums;
}
}
?>
Hope it will be helpful for you.