[英]How to query a database with an array in the where clause in PHP?
Hi guys I am trying to select all the users in my database with an array of USER ID.大家好,我正在尝试使用一组用户 ID 选择数据库中的所有用户。 I am coding in PHP and this is my code so far but I get an error saying I am trying to use an array.
我正在用 PHP 编码,这是我到目前为止的代码,但我收到一个错误消息,说我正在尝试使用数组。
$relative = $this->db->select('user_id, fname, surname')->get_where('user_view_view', array('user_id'=>$mytest))->result_array();
My array of user ids is called:我的用户 ID 数组称为:
$mytest
What am I doing wrong?我究竟做错了什么?
try something like that尝试这样的事情
$query = $this->db
->select('user_id, fname, surname')
->from("user_view_view")
->where_in("user_id",$myTest)
->get();
$relative = $query->result_array();
the reason why it won't work is because get_where doesn't accept an array as field_value它不起作用的原因是因为 get_where 不接受数组作为 field_value
you should get an error with the message "Array to string conversion"您应该收到消息“数组到字符串转换”的错误消息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.