Ernestoale97
Ernestoale97

Reputation: 40

Load automatically the rows in TabularForm Yii2

Iam trying to make this:

I need that when I create a new poll, it loads the aspects and a dropdown with the valorations choices list from the database like this:

enter image description here

I have a table for aspects, and another for valorations, which is a number from 1 to 5. Normally, when I create a new poll i have to add manually all the rows and select the aspect and the valoration, but in this way its too much job, so i want it to load all the aspects and it would just need to set the valoration for each row and save it. thanks and sorry for my english

Upvotes: 0

Views: 85

Answers (1)

himanshu
himanshu

Reputation: 125

As far as I can understand your query, you want something like this:

You have a database table: Aspects (which I expect has static data) You have a database table: valorat.(which I expect has static data of 1-5)

Now, whenever you create a new poll, it should automatically populate itself with the aspects and valoration dropdown table.

If I am right, you can try the following logic,

You can run the following logic

//run a loop for each aspect row fetched from database
<?php foreach($aspects as $value): ?>
    <tr>
       <td>
        //here goes the id
       </td>

       <td>
          <?= $value ?> //here goes your aspect value
       </td>

       <td>
          <select>
             //here run a loop for valorations you fetched from database
             <?php  foreach($valoration as $key=>$value): ?>
                <option value="<?=$key?>"><?= $value ?></option>
             <?php endforeach; ?>
          </select>
       </td>
    </tr>
<?php endforeach; ?>

In this way, you can achieve the desired table with the aspects and valoration.

If you are using the Yii2 grid view, it is far more simple than this. But without looking at your code and database tables, I can't give you more.

Thank You!! I hope you will get some idea how to do this.

Upvotes: 0

Related Questions