How to properly view table data using if statement in yii2

蓝咒 提交于 2020-07-31 04:11:40

问题


I am working on yii2. I have a page in which I have created a table. Now I want to put some data into it via my database query using if....else statement.

<tbody style="text-align: center; line-height: 12px">
<?php
                    $bd = $dataProvider2->getModels();
                    foreach ($bd as $a)
                    {
                        $strt =$a['slab_start'];
                        $end = $a['slab_end'];
                        $rate = $a['rate'];
                        if ($end !='')
                        {
                            echo "<tr>
                                <td>".print_r($strt).".".print_r('-').".".print_r($end)."</td>
                                <td>".print_r($rate)."</td>

                            </tr>";
                        }
                        else
                        {
                            echo "<tr>
                                <td>".print_r('upto')."</td>
                                <td>".print_r($rate)."</td>

                            </tr>";
                        }
                    }

                    ?>
</tbody>

But when I try to view my page, the above data is not properly shown

It's not going inside the <tbody>.

Expected output


回答1:


Just don't use print_r inside echo:

<tbody style="text-align: center; line-height: 12px">
<?php
                    $bd = $dataProvider2->getModels();
                    foreach ($bd as $a)
                    {
                        $strt =$a['slab_start'];
                        $end = $a['slab_end'];
                        $rate = $a['rate'];
                        if ($end !='')
                        {
                            echo "<tr>
                                <td>".$strt ."-". $end ."</td>
                                <td>".$rate."</td>

                            </tr>";
                        }
                        else
                        {
                            echo "<tr>
                                <td>upto</td>
                                <td>".$rate."</td>

                            </tr>";
                        }
                    }

                    ?>
</tbody>


来源:https://stackoverflow.com/questions/63148838/how-to-properly-view-table-data-using-if-statement-in-yii2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!