EllisLab text mark
Advanced Search
     
Query from multiple tables
Posted: 01 May 2011 04:12 AM   [ Ignore ]
Joined: 2011-05-01
1 posts

Hi All,

I am a beginner in codeigniter. Could you please help me.

I want to return result from two tables.

The table structures are as given below.

1user :   id     int(11), username varchar(16),status tinyint(1)
2transaction id int(11), tranType varchar(20),status tinyint(1) ,userid int(11

Here relation between user and transaction table is one to many and I want to show the max record from transaction table grouping by user.id.

for example

user table has the following records

ID userName status
1       John     1
2       James   1

transaction table has the following records

Id TranType   Status userID
1     signup     1     1
2     payment     1     1
3     approved   1     1


so here it should return the result as follow

user.ID userName,TranType userStatus Tran Status
1           John   approved     1       1

 
How can I write a query for codeigniter joining the both tables and return the result with specific columns.

[user.Id,user.userName,transaction.tranType,user.status,transaction.status] 

Many appreciation for you quick reply

thanks

 
Posted: 01 May 2011 11:47 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-04-30
45 posts

$query = “SELECT * FROM tbl1 LEFT JOIN tbl2 “.
  “ON tbl1.ID = tbl2.ID WHERE tbl1.id = 1”

$this->db->query($query);

try this.im not sure.but i hope it helps.


:D

 Signature 

Pinoy/PHP Developer/Codeigniter

My Blog