Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to show data with ajax using codeigniter

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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'].',%"
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading