CodeIgniter Forums
unable to fetch records from database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: unable to fetch records from database (/showthread.php?tid=64035)



unable to fetch records from database - nady - 01-06-2016

Hi
whats wrong in my following query. i got the error
Error Number: 1054
Unknown column 't.user_id' in 'where clause'
-------------------------my query------------

function ShowTransData($data){
$this->db->select('*')
->from('transaction')
->join('user', 'transaction.user_id = user.user_id')
->where('t.user_id='. $data);
$query = $this->db->get();
return $query->result();


RE: unable to fetch records from database - mr_pablo - 01-06-2016

(01-06-2016, 02:16 AM)nady Wrote: Hi
whats wrong in my following query. i got the error
Error Number: 1054
Unknown column 't.user_id' in 'where clause'
-------------------------my query------------

function ShowTransData($data){
$this->db->select('*')
->from('transaction')
->join('user', 'transaction.user_id = user.user_id')
->where('t.user_id='. $data);
$query = $this->db->get();
return $query->result();

You are trying to get `t.user_id` but you have not assigned `t` to the `transaction` column

PHP Code:
function show_trans_data($data){
    
$this->db->select('*')
    ->
from('transaction as t')
    ->
join('user''t.user_id = user.user_id')
    ->
where('t.user_id'$data); // I'm guessing this is just an ID number?

    
$query $this->db->get();

    return 
$query->result();


I also tidied up your function.


RE: unable to fetch records from database - Dhiren - 01-06-2016

Try the following code:


PHP Code:
function show_trans_data($data){
 
   $this->db->select('*')
 
   ->from('transaction as t')
 
   ->join('user''t.user_id = user.user_id')
 
   ->where('t.user_id = "' $t.user_id '"');

 
   $query $this->db->get();

 
   return $query->result();