0

我一直在尝试使用 PHP 在 Yii 的表中创建行,但不知何故我无法做到这一点。我附上了下面的代码。

PHP代码:

<div class="grid_16">
<table style="width:100%">
<tr>
<th style="width:33%;" id="wall_userNameStyle"><?php echo CHtml::activeLabel($Facility,'cname'); ?></th>
<th style="width:33%;margin:0 0.5%" id="wall_userNameStyle"><?php echo CHtml::activeLabel($Facility,'cregistration'); ?></th>
<th style="width:33%" id="wall_userNameStyle"><?php echo CHtml::activeLabel($Facility,'cannual'); ?></th>
</tr>

<?php $j=0;
for($j; $j<5; $j++)
{
?>
<tr>
<td style="width:33%;"><?php echo CHtml::activeTextField($Facility,"raymond[$j][0]",array('class' => 'edit_textbox','style' => 'width:99%')) ; ?></td> 

<td style="width:33%;margin:0 0.5%"><?php echo CHtml::activeTextField($Facility,"raymond[$j][1]",array('class' => 'edit_textbox','onkeypress'=>'return number_only(event)','style' => 'width:99%')) ; ?></td> 

<td style="width:33%;"><?php echo CHtml::activeTextField($Facility,"raymond[$j][2]",array('class' => 'edit_textbox','onkeypress'=>'return number_only(event)','style' => 'width:99%')) ; ?></td>
</tr>
</table>
<?php } ?>
</div>
4

3 回答 3

3

您需要放在</table>for 循环之外。

于 2012-12-21T18:59:26.487 回答
2

你需要的是

<?php 
for($j = 0; $j<5; $j++)
{
?>
<tr>
<td style="width:33%;"><?php echo CHtml::activeTextField($Facility,"raymond[$j][0]",array('class' => 'edit_textbox','style' => 'width:99%')) ; ?></td> 

<td style="width:33%;margin:0 0.5%"><?php echo CHtml::activeTextField($Facility,"raymond[$j][1]",array('class' => 'edit_textbox','onkeypress'=>'return number_only(event)','style' => 'width:99%')) ; ?></td> 

<td style="width:33%;"><?php echo CHtml::activeTextField($Facility,"raymond[$j][2]",array('class' => 'edit_textbox','onkeypress'=>'return number_only(event)','style' => 'width:99%')) ; ?></td>
</tr>
<?php } ?>

</table>
</div>

</table>在循环的一侧关闭了你的桌子

于 2012-12-21T18:58:30.440 回答
1

你可以试试:

<table>
<th>
//information
</th>
<tr>
<?php
$j = 0;
for($j = 0; $j<5; $j++)
{
echo "<td>";
echo //table information 1
echo "</td>";
echo "<td>";
echo //table information 2
echo "</td>";
echo "<td>";
echo //table information 3
echo "</td>";
}
?>
</tr>
</table>

表格信息可以是任何东西或任何数量。

于 2012-12-21T19:08:05.227 回答