加入得到4个表所有结果由id

时间:2017-03-10 19:25:05

标签: php mysql codeigniter

问题

现在我在codeigniter中编辑表单,我想获取所有四个表数据。从控制器来到event_id,通过这个id,我想得到数据。

模型

public function get_list_for_edit($event_id){
    return

   $this->db->select('*')
            ->from('events e')
            ->join('events_location el','el.events_id =' $event_id,'left')
            ->join('events_photos ep',
                    'ep.events_id =' $event_id,'left')
            ->join('push_notifications pn',
                    'pn.events_id =' $event_id,'left')
            ->where('e.event_id =' $event_id)
            ->row_object();
 }

错误

消息:语法错误,意外' $ event_id' (T_VARIABLE)

1 个答案:

答案 0 :(得分:0)

可能是你需要字符串连接(不正确地将变量添加到字符串的其余部分)

  public function get_list_for_edit($event_id){
      return

     $this->db->select('*')
              ->from('events e')
              ->join('events_location el','el.events_id =' . $event_id,'left')
              ->join('events_photos ep',
                      'ep.events_id =' . $event_id,'left')
              ->join('push_notifications pn',
                      'pn.events_id ='. $event_id,'left')
              ->where('e.event_id =' . $event_id)
              ->row_object();
   }

用于调用未定义的方法CI_DB_mysqli_driver :: row_object()错误
您没有选择表格名称...因此您应该为所需的表格/模型添加get(' TABLE_NAME')方法

     $this->db->select('*')
              ->from('events e')
              ->join('events_location el','el.events_id =' . $event_id,'left')
              ->join('events_photos ep',
                      'ep.events_id =' . $event_id,'left')
              ->join('push_notifications pn',
                      'pn.events_id ='. $event_id,'left')
              ->where('e.event_id =' . $event_id)->get('TABLE_NAME')
              ->row_object();