如何在Codeigniter中打印值?

时间:2017-01-28 05:18:41

标签: php html codeigniter

如何在Codeigniter中打印值? 我有以下代码:

<table>
<tr>
<?php 
foreach($assigned_qu[0] as $key => $qu){
?>
<td id="qtd4"><?php echo $key;?></td>
<?php
}
?>
</tr></table>

它给出了:

<tr><td id="qtd4">ex1</td>
<td id="qtd4">ex2</td>
<td id="qtd4">ex3</td>
<td id="qtd4">ex4</td>
</tr> 

我想要这样的打印值:

<tr>  <td id="qtd4">ex1</td> /* how to print `<tr></tr>` tags? */
<td id="qtd4">ex2</td>  </tr>
<tr>  <td id="qtd4">ex3</td>
<td id="qtd4">ex4</td>  </tr>

如何在td代码

之间打印两个tr代码

3 个答案:

答案 0 :(得分:1)

   <?php
    foreach ($assigned_qu as $qu):
        ?>

    <tr><td id="qtd4"><?php echo $qu->table_column_name;?></td></tr>
    <?php } ?>

答案 1 :(得分:0)

以下是关于如何根据您的问题显示表格的PHP代码:

<table>
    <?php 
        foreach($assigned_qu[0] as $key => $qu){
            ?>
                <tr>
                    <td id="qtd4"><?php echo $key;?></td>
                </tr>
            <?php
        }
    ?>
</table>

答案 2 :(得分:0)

试试这个问题:
  

<?php 
$cnt=0;
foreach($assigned_qu[0] as $key => $qu){
    if($cnt%2 == 0){
        echo "<tr>";
    }
?>
<td id="qtd4"><?php echo $key;?></td>

<?php
$cnt++;
if($cnt%2 == 0){
        echo "</tr>";
    }   
}
?>
</table>