如何使用codeigniter显示 AJAX 数据

rbl8hiat  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(143)

我有表项

id |    name    | location
1  |   item a   |   3,5 
2  |   item b   |   4

这里我做了一个模型

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 =参数是位置
这里作为一个例子,参数中的内容是3为什么不显示?
如何显示数据,如果参数为3则显示item a如果参数为5则显示item a

sh7euo9m

sh7euo9m1#

位置必须是数组。请使用where_in代替where

$this->db->where_in("location", [$postData['location']]);

或使用

WHERE (location ='.$postData['location'].' 
OR location LIKE "'.$postData['location'].',%"
OR location LIKE "%,'.$postData['location'].'"
OR location LIKE "%,'.$postData['location'].',%"
)

相关问题