如何在codeigniter中编写sql查询

时间:2017-04-12 10:50:00

标签: php codeigniter

如何在codeigniter中编写此代码? 我想在php codeigniter中转换此代码。

$query="SELECT * FROM class,student 
   WHERE class.class_name= '$name' AND student.class_id='$name'";

2 个答案:

答案 0 :(得分:0)

尝试使用有效记录

$this->db->select('*');
$this->db->from('class');
$this->db->join('student', 'student.id = class.student_id'); // check the join i.e the common column
$this->db->where('class_name', $name);
$this->db->where('class_id', $name);

答案 1 :(得分:0)

尝试此查询....

    $this->db->where('class_name',$name);
    $this->db->select('*');
    $this->db->from('class');
    $this->db->join('student', 'student.class_id = class.class_name');
    $query = $this->db->get();
    return $query->result();