Reputation: 105
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
Upvotes: 1
Views: 810
Reputation: 4321
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>
Upvotes: 0
Reputation: 16436
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>
Upvotes: 0
Reputation: 650
<?php
foreach ($assigned_qu as $qu):
?>
<tr><td id="qtd4"><?php echo $qu->table_column_name;?></td></tr>
<?php } ?>
Upvotes: 1