Welcome Guest, Not a member yet? Register   Sign In
Finding Difficulties with some SQL
#1

[eluser]Shahidul[/eluser]
Hello
I'm a beginner with CI

Now in difficulties with some SQL.

I want to retrieve data from mysql. the traditional query is like the following.

SELECT t.tdl_name, t.tdl_description, t.tdl_author, c.company_name, c.company_address, d.developer_name FROM tdl_info t, company_info c, developer_info d WHERE t.tdl_id = 1 AND c.company_id = t.tdl_id AND d.developer_id = t.developer_id


Which retrieve a single row from three tables. tdl_info, developer_info, company_info where tdl_id = 1 from table tdl_info.

How to implement this query within CI.

Thanks
Shahidul
#2

[eluser]reset[/eluser]
Hello Shahidul,

Your query could be that:

Code:
$this->db->select('t.tdl_name, t.tdl_description, t.tdl_author, c.company_name, c.company_address, d.developer_name');
$this->db->from('tdl_info t');
$this->db->join('company_info c', 'c.company_id = t.tdl_id');
$this->db->join('developer_info d', 'd.developer_id = t.developer_id');
$this->db->where('t.tdl_id ',1);
#3

[eluser]gtech[/eluser]
or you can cheat, and just manually write the sql statement.

$query = $this->db->query("SELECT t.tdl_name, t.tdl_description, t.tdl_author, c.company_name, c.company_address, d.developer_name FROM tdl_info t, company_info c, developer_info d WHERE t.tdl_id = 1 AND c.company_id = t.tdl_id AND d.developer_id = t.developer_id");

[url="http://ellislab.com/codeigniter/user-guide/database/queries.html"]http://ellislab.com/codeigniter/user-guide/database/queries.html[/url]
#4

[eluser]Shahidul[/eluser]
Thank you very much for your help. This will help me very much.


Thanks again.
Shahidl




Theme © iAndrew 2016 - Forum software by © MyBB