Welcome Guest, Not a member yet? Register   Sign In
Having trouble with Active Record database query
#1

[eluser]lennierb5[/eluser]
I am trying to display a list of data using the table & pagination library. When I run the first query the rows are counted properly and data is returned but when I use the Active Record query nothing is returned.

Is there any way to view the query codeigniter has created before executing it to see where the error is??

Here is my code:

Code:
$query = $this->db->query("
                                  SELECT job_data.job_data_id, a_techs.tech_number, job_data.date, job_data.account_num, job_data.c_address, job_data.c_apt, job_data.job_status
                                  FROM job_data, a_techs
                                  WHERE job_data.tech_id = a_techs.a_techs_id
                                  ");
        $total_rows = $query->num_rows();
        $per_page = 20;
        $query->free_result();
        $this->db->select('job_data.job_data_id, a_techs.tech_number, job_data.date, job_data.account_num, job_data.c_address, job_data.c_apt, job_data.job_status');
        $this->db->from('job_data, a_techs');
        $this->db->where('job_data.tech_id', 'a_techs.a_techs_id');
        $this->db->limit($per_page);
        
        if ($this->uri->segment(3) !== FALSE)
        {
           $this->db->offset($this->uri->segment(3));
        }
        
        $query = $this->db->get();
#2

[eluser]TheFuzzy0ne[/eluser]
Add this to the top of the method or the controller constructor:
Code:
$this->output->enable_profiler(TRUE);

This will allow you to see the queries being executed, so long as there's no fatal error triggered before the final output is sent to the browser.

I think you're problem might have something to do with your FROM clause. I think it might work if you do this:
Code:
$this->db->select('job_data.job_data_id, a_techs.tech_number, job_data.date, job_data.account_num, job_data.c_address, job_data.c_apt, job_data.job_status');
$this->db->from('job_data');
$this->db->join('a_techs', 'job_data.tech_id = a_techs_a_techs_id', 'INNER');
$this->db->limit($per_page);

if ($this->uri->segment(3) !== FALSE)
{
   $this->db->offset($this->uri->segment(3));
}
        
$query = $this->db->get();
#3

[eluser]lennierb5[/eluser]
Thanks for your help, I tried the suggested query and it worked perfectly.

I will keep the enable_profiler option for further query problems.




Theme © iAndrew 2016 - Forum software by © MyBB