简体   繁体   中英

How to print values in Codeigniter?

How to print values in Codeigniter? I have following code:

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

It gives:

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

I want print values like this:

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

How do print two td tags between tr tag

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

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

Here is the php code on how to display a table as per your question:

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

Try this soltion :

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM