Welcome Guest, Not a member yet? Register   Sign In
Can CI accept a variable as the full join syntax? [SOLVED]

(This post was last modified: 08-01-2021, 01:35 AM by InsiteFX.)

I created a model which supports a generic database GET request and if you include data from the $joinArray then it will loop through the values of this array and create $builder->join($joinArray);

Unfortunately I can't get this to work.

To keep it short I would like to do the following:
    $joinData = array(
        0 => "'table AS k', 'k.something = j.anotherthing', 'left'"

        foreach($joinData as $key => $value){

In the end, it should behave like this:
     $builder->join('table AS k', 'k.something = j.anotherthing', 'left');

thank you for your time!

Answered, look below for the code if you're having the same issue as me

PHP Code:
$joinData = [
            0 => [
                'table' => 'table AS k',
                'condition' => 'k.something = j.anotherthing',
                'type' => 'left',
            1 => [
                'table' => 'table AS t',
                'condition' => 't.something = j.anotherthing',
                'type' => 'left',

        if (!empty($joinData)) {
            foreach($joinData as $key => $join){
                $builder->join($join['table'], $join['condition'], $join['type']);

Thank you for your response!

The answer provided works like a charm. I was also pointing to a very similar but wrong function which didn't help matters. hah.

Theme © iAndrew 2016 - Forum software by © MyBB