problem with where in codeIgniter


problem with where in codeIgniter

如果使用此代码,请显示所有数据,所有名称和所有id。我该怎么办?
使用codeIgniter

关于

$search_customer = 1;//$this->input->post('search_customer');
$where = "id=$search_customer OR name=$search_customer";
$query = $this->db->get('customer');
$this->db->where('id', $search_customer);
$this->db->or_where('name', $search_customer);
if($query->num_rows()==0){
            echo '0';
        }else{
            $data = array();
            foreach ($query->result() as $row)
            {
               $data[] = $row;
            }
            echo json_encode($data);
        }

在以下条件下试试:

$this->db->where('id', $search_customer);
$this->db->or_where('name', $search_customer);

你可以在文档中看到get_where使用了一个关联数组

看起来就像错误告诉你的那样。数据库中没有名为"id=1"的列

尝试使用数组

$array = array('id'=>$search_customer);
$this->db->get_where('customers', $array);

http://codeigniter.com/user_guide/database/active_record.html选择

还有or_where可用:

$this->db->or_where('name', $search_customer);

这一行运行查询:

$query = $this->db->get('customer');
在设置where子句之前使用

。你可能想要

$this->db->where('id', $search_customer);
$this->db->or_where('name', $search_customer);
$query = $this->db->get('customer');

如果你仍然有问题,看看正在生成的sql/运行:

echo $this->db->last_query();