0

I am beginner in using codeigniter query builder class. and I got a problem in converting this query using query builder class.

SELECT tb_country.`countryName`, COUNT(tb_country.countryId) AS totalCustomer FROM tb_customer 
    JOIN tb_city ON tb_city.`cityId` = tb_customer.`cityId`
    JOIN tb_state ON tb_state.`stateId` = tb_city.`stateId`
    JOIN tb_country ON tb_country.`countryId` = tb_state.`countryId`
GROUP BY tb_country.`countryName`

any answers will be helpful to me, thanks in advance!

1 Answer 1

1
$this->db
     ->select("tb_country.countryName, COUNT(tb_country.countryId) AS totalCustomer", false)
     ->from('tb_customer')
     ->join('tb_city', 'tb_city.cityId = tb_customer.cityId')
     ->join('tb_state', 'tb_state.stateId = tb_city.stateId')
     ->join('tb_country', 'tb_country.countryId = tb_state.countryId')
     ->group_by('tb_country.countryName')
     ->get()
     ->result();
Sign up to request clarification or add additional context in comments.

4 Comments

what is the meaning of 'true' in the third parameter of select function?
sorry it should be false. it means codeigniter not to protect the select statement. it is required because, there is compound select statement, i.e count() in our select, hence set that second argument to false
check once whether it works or not, these days i am not using codeigniter so i m not sure.
I think the third parameter is not required, it still works even after I remove it. But, thanks man it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.