Just refer to codeigniter user guide here And i suggest if you are not compatible on doing that way try to code like this:
$sql = "SELECT * FROM $table_name";
$this->db->query($sql);
It is just the same way around.
Question
I'm very new to the concept of joining two tables in CodeIgniter query. Can someone explain the meaning of each line of these codes, please? I don't understand them at all.
$this->db->select('d.*, u.first_name, u.last_name');
$this->db->where('status', -1);
$this->db->join('users AS u','u.id = d.user_id');
$this->db->order_by('d.date','desc');
return $this->db->get('dtr AS d');
La solution 2
Just refer to codeigniter user guide here And i suggest if you are not compatible on doing that way try to code like this:
$sql = "SELECT * FROM $table_name";
$this->db->query($sql);
It is just the same way around.
Autres conseils
Joins is not a CodeIgniter concept but a relational database concept. The SQL code of this query is :
SELECT d.*, u.first_name, u.last_name'
FROM dtr AS d
INNER JOIN users AS u ON u.id = d.user_id
WHERE status = -1
ORDER BY d.date DESC
the query calls two table and joins them using a common key (user: id and dtr: id).