Welcome Guest, Not a member yet? Register   Sign In
Using count_all_results or get_compiled_select with $this->db->get()

How do I use get_compiled_select or count_all_results before running the query without getting the table name added twice? When I use $this->db->get('tblProgram') after either of those, I get the error:
Not unique table/alias: 'tblProgram'

SELECT * FROM (`tblProgram`, `tblProgram`) JOIN `tblPlots` ON `tblPlots`.`programID`=`tblProgram`.`pkProgramID` JOIN `tblTrees` ON `tblTrees`.`treePlotID`=`tblPlots`.`id` ORDER BY `tblTrees`.`id` ASC LIMIT 2000

Here is my code:
public function get_download_tree_data($options=array(), $rand=""){

//join tables and order by tree id
  $this->db->order_by('tblTrees.id', 'ASC');

//get number of results to return
  $allResults=$this->db->count_all_results('tblProgram', false);

//chunk data and write to CSV to avoid reaching memory limit
  while (($offset<$allResults)) {
      $this->db->limit($chunk, $offset); 
      foreach ($result as $row) {
          fputcsv($tree_handle, $row);
    return array('resultCount'=>$allResults);


(This post was last modified: 03-29-2022, 01:08 AM by ignitedcms.)

If you have two duplicate column names in two or more different tables and you're doing a 'join' you have to specify an alias I believe.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com

Theme © iAndrew 2016 - Forum software by © MyBB