I have an array like this
Array (
[14] => 0.46902846738366
[16] => 0.40289063077504
[17] => 0.54903658244928
)
14, 16, 17 are at the same array key id of my tables that are in the database. how do I can access my information from a database table based on the key array (14, 16, 17)?
we assume that in the table there is a lot of data that is stored but I just wanted to take the data with id 14, 16, 17. The selected later from the id that I will perform mathematical operations to find the value of the highest of the three.?
$arry = array(14 => 0.46902846738366,16 => 0.40289063077504,17 =>0.54903658244928 );
$idarray=array_keys($arry);
"SELECT data FROM table WHERE id IN (".implode(',',$idarray).")";
$myArray = array (
'14' => 0.46902846738366,
'16' => 0.40289063077504,
'17' => 0.54903658244928,
) ;
$myArrayForQuery = implode(',',array_keys($myArray));
$myQuery = 'SELECt * FROM mytable where id in ( '.$myArrayForQuery.' );';
to get rows using ids put this code in your model(let's call it model)
function get($ids) {
return $this->db->where_in('id', $ids)->order_by->('my_col_name')->get('storage')->result(); // or result_array();
}
and call it like this
$data = $this->model->get(array_keys($zip_array));// or $this->model->get($array_a); from your last question
data in $data will be sorted from max value to low value, so automatically you got the max one too ! just need to change my_col_name to your column name
update: of course you can only select max value, if you want this, change get() to this
return $this->db->where_in('id', $ids)->select_max('my_col_name')->get('storage')->row();