问题
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