i have tabel_item
id | name | location
1 | item a | 3,5
2 | item b | 4
here I made a model
public function db_barangGetMaster($postData){
if(isset($postData['location']) ){
$this->db->select("*");
$this->db->from('tabel_item as a');
$this->db->where("location", $postData['location']);
$response = array();
$query = $this->db->get()->result();
foreach($query as $row ){
$response[] = array(
"id" =>$row->id,
"name" =>$row->name,
"lokasi" =>$row->location
);
}
if (count($response)) {
return $response;
} else {
return ['response' => 'not found'];
}}
}
$postData = parameter is location
here as an example the content in the parameter is 3 why not show?
how to display the data, if the parameter is 3 then what appears is item a if the parameter is 5 then item a
CodePudding user response:
location must be array. use where_in
instead of where
$this->db->where_in("location", [$postData['location']]);
Or use
WHERE (location ='.$postData['location'].'
OR location LIKE "'.$postData['location'].',%"
OR location LIKE "%,'.$postData['location'].'"
OR location LIKE "%,'.$postData['location'].',%"
)