How To Use Join To Retrieve Data From Two Tables And Display Their Results In Cgridview

Hello guys, how are you ?

I have three tables “A”, “B” and “C”, all the tables have ‘name’ fields, now I am saving the “B” and “C”'s table data in table “A” such that I am changing the field display property using javascript and can save both the tables i.e. “B” and “C” data in either field. Now In “A”'s admin gridview I want to display both fields data that I have stored in “A” table and it displays the ids of all those records. Now I want to display the ‘name’ of the records of “B” and “C”'s tables instead of their ids. So how can I do this ?

One option is to use Joins and Unions. But I don’t have that concept.

Please anyone who knows the solution help me ?

Thanks in advance…

Your question is kinda confusing. I don’t know what you’re trying to do with the JS…It sounds like you just want to show relating data names inside a gridview it would be something like




array(

'name'=>'Table_B_Name',

'header' => 'Name',

'value'=>'$data->relationNameB->name'

),

array(

'name'=>'Table_C_Name',

'header' => 'Name',

'value'=>'$data->relationNameC->name'

),



http://www.yiiframew…en/database.arr

Thanks sir for your reply.

Actually I have 3 models i.e. "A", "B" and "C", in "A" model I have two fields (lets say "b" and "c") . and I also have a radio button which is used to change the position of the text fields "b" and "c", in "a" I can save the "B" table id and "C" table id, and in "c" I can save the "B" table id and "C" table id. i.e. in both the text fields I can save both of the tables id.

Now in gridview I want to display the "b" field and "c" field data, but instead of ids, I want to display the "B" and "C" tables "name" fields values. but it gives error. since in both of the fields i.e. "b" and "c" I have saved both of the tables ids, so in gridview how can we distinguish them ??

Should we use some conditions on Relations or what should I do ?