【发布时间】:2018-07-04 11:49:42
【问题描述】:
我正在尝试减少模型中的所有方法,因此我决定使其成为动态的。已完成为插入、更新、获取、删除创建动态,但在创建用于连接 2 个表的动态时遇到问题。
遇到错误:
"函数 CI_DB_query_builder::join() 的参数太少,通过了 1 个 在 C:\xampp\htdocs\snapmatic\application\models\Crud_model.php 上线 130 和至少 2 预期"`
注意:在这个项目中,我正在做的模块是“关注”,用户可以关注特定的人(如 instagram)。我有 2 个表名为:用户和关注。
在我的“下表”中,我的列是:id、user_id 和 user_following。 user_id 是帐户登录的位置,而 user_following 是您关注的帐户。
Scenario: In my table users, you have 2 data: Person 1 and Person 2
Person 1 account is logged in then Person 1 followed Person 2.
在第 1 个人点击按钮后,在我的关注表中将如下所示:
id: 1 user_id: 1 user_follow:2
这是我的控制器
$id = $this->session->user_id;
$where = array('following.user_id => $id');
$join = array('following,following.user_following = users.id');
$fetch_following = $this->Crud_model->join_table('*','users',$where,$join);
//Also tried these
//$where = "('following.user_id', $id)";
//$where = "'following.user_id', $id)";
//$where = "('following.user_id, $id')";
//$where = "'following.user_id, $id'";
//$join = "'following,following.user_following = users.id'";
//$join = "('following,following.user_following = users.id')";
//$join = "('following','following.user_following' = 'users.id')";
型号
public function join_table($tag,$table,$where,$join){
// public function join_table($id){
$this->db->select($tag);
$this->db->from($table);
$this->db->join($join);
$this->db->where($where);
// $this->db->select('*');
// $this->db->from('users');
// // $this->db->group_by('invoice_number');
// $this->db->join('following','following.user_following = users.id');
// $this->db->where('following.user_id', $id);
$result = $this->db->get();
return $result->result();
}
评论部分正在工作,但我想让它成为动态的。
问题:如何制作动态加入表格的方法?
【问题讨论】:
-
我想是
$join = array('following' ,'following.user_following = users.id');看看 quotes 使你的数组成为一个包含 2 个元素的数组? -
其实先生,我也试过了,但有同样的错误。
标签: php codeigniter codeigniter-3 codeigniter-query-builder