phpcodeigniterjoinselectquery-builder

codeigniter join table by number and not a nother table


When i try to make a this join in codeigniter

$this->db->join('ticketsale','ticketsale.id = 1');

i get this error: Unknown column '1' in 'on clause'

"SELECT * FROM (`users`) JOIN `ticketsale ` ON `ticketsale `.`id` = `1` JOIN `ticketsale_.."

how do I get codeigniter to not putting `` around 1?


Solution

  • Because in join statement, You must use column name for match them and joining other query.If you want to do that, you should add Where statement. For example:

    "SELECT * FROM (`users`) JOIN `ticketsale ` ON `ticketsale `.`id` = `hereyourtable`.`hereis the column` JOIN `ticketsale_..  WHERE `ticketsale `.`id`=1"
    

    UPDATED: Also, In active records;

     $this->db->join("ticketsale","ticketsale.id=users.column")->where("ticketsale.id"=>"1");
    this query will return same as native sql query