【发布时间】:2013-07-27 23:26:52
【问题描述】:
我想通过数组从控制器发送 2 个字符串到模型并从 db 中获取结果,但是我遇到了一个问题。
我的控制器是这样的:
$data = array();
if($query = $this->authors_model->get_authors_list(array('author_Type' => array('admin', 'author'))))
{
$data['authors'] = $query;
}
我的模特:
function get_authors_list($options = array())
{
if(isset($options['author_Type']))
$this->db->where('author_Type', $options['author_Type']);
$this->db->order_by('author_Id', 'ASC');
$query = $this->db->get('mg_authors');
return $query->result();
}
以及我得到的错误:
遇到了 PHP 错误
严重性:通知
消息:数组到字符串的转换
文件名:数据库/DB_active_rec.php
行号:427
错误号:1054
“where 子句”中的未知列“数组”
SELECT * FROM (
mg_authors) WHEREauthor_Type= 数组 ORDER BYauthor_IdASC 限制 15文件名:D:\xampp\htdocs\sport\system\database\DB_driver.php
行号:330
【问题讨论】:
-
您将
$options['author_Type']数组传递给AR::where()方法,该方法生成author_Type = Array。这是一个错误。
标签: arrays codeigniter where-clause