[eluser]chazy (aldever calvo)[/eluser]
hello i really need help in joining tables for my get function
i have 3 tables:
user
-----
user_id(pk)
user_type_id(fk)
user_det_id(fk)
user_type
---------
user_type_id(pk)
user_details
------------
user_det_id(pk)
i had it joined and successfully output the result... but the problem is... i cannot do pagination with it...
my past code is this
Code:
function GetAllDetails()
{
$q = "SELECT A.user_id, A.uname, A.user_type_id, D.user_det_id, D.lname, D.fname, D.mname, D.email, T.user_type_name FROM user as A LEFT JOIN user_details as D ON A.user_id = D.user_det_id LEFT JOIN user_type as T ON A.user_type_id = T.user_type_id";
$query = $this->db->query($q);
return $query->result();
}
and so what i did is change it into:
Code:
function GetAllDetails()
{
$this->db->join('choy_user_details', 'choy_user.choy_user_id = choy_user_details.choy_user_det_id');
$this->db->join('choy_user_type', 'choy_user.choy_user_type_id = choy_user_type.choy_user_type_id', 'left');
$this->db->where('choy_user_id', $userId);
$query = $this->db->get('choy_user');
return $query->result();
}
But i have errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: userId
Filename: models/user_model.php
Line Number: 45
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: database/DB_driver.php
Line Number: 616
Please help me...