【问题标题】:How to query a database with an array in the where clause in PHP?如何在 PHP 的 where 子句中使用数组查询数据库?
【发布时间】:2015-11-20 13:50:46
【问题描述】:

大家好,我正在尝试使用一组 USER ID 选择数据库中的所有用户。我正在使用 PHP 进行编码,这是我目前的代码,但我收到一条错误消息,提示我正在尝试使用数组。

$relative = $this->db->select('user_id, fname, surname')->get_where('user_view_view', array('user_id'=>$mytest))->result_array();

我的用户 ID 数组被调用:

$mytest

我做错了什么?

【问题讨论】:

标签: php mysql arrays codeigniter


【解决方案1】:

试试类似的方法

$query = $this->db
    ->select('user_id, fname, surname')
    ->from("user_view_view")
    ->where_in("user_id",$myTest)
    ->get();

$relative = $query->result_array();

它不起作用的原因是因为get_where不接受数组作为field_value

您应该会收到一条错误消息“数组到字符串转换”

【讨论】:

  • 我的页面只是加载空白,这意味着代码中有错误。
  • 将环境设置为开发 - 如果没有错误消息,我真的无法提供帮助
猜你喜欢
  • 1970-01-01
  • 2014-06-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 2014-01-01
  • 1970-01-01
  • 2018-04-14
  • 1970-01-01
相关资源
最近更新 更多