How to show data from multiple table

Dear Yii Gamers :)

I have table A, saving : id, name, basic_salary

table B, saving : periode, allowance

I want to show data like this :

Dear %name%

Herewith your monthly salary = %basic_salary%

and allowance = %allowance%

subtotal = %basic_salary% + %allowance%

less :

2% THT -> the formula is 2% * %basic_salary%

total = %basic_salary% + %allowance% - 2% THT

how should I do ? since so far i just play with model, view, gii, crud. so I dont know yet where to code.

Please help from newbie next door :)


1 - If the both tables have any thing that is related then you can use one table PK to get the other table’s data that is related with it using Relations in your model.

2 - If Currently both the tables are not related to each other, then you must have to set an algorithm that will manipulate to bring the required data out from DB.

For the first case, in your model of each of the table, when you define the relation, you can access the data by using the with property of the model and can use it as



Thank you PeRoChAk, in my case both table are not related to each other.

Could you straight to the example, since I’m not really understand what you mean by set an algorithm. I do understand PHP and MySQL syntax. If I do it with pure PHP, not Yii, I will do something like this :

$sql = "select * from table A where id='something'" 

  While {

    $id = row->id

    $name = row->name

    $salary = row->basic_salary

    "select allowance from table B where id=$id"

   while {

    $allowance = row->allowance

    $addvalues = $salary+$allowance

     echo "$id - $name - $basic_salary ";

     echo "            - $allowance";

     echo "----------------------------";

     echo " total      = $addvalues";

  } //end 2nd while

} // end 1st while

how shall I do in Yii ?