Php 引导和codeIgniter数据显示在表中
我正在从数据库中提取数据。我想在表中显示该数据,但我想在一行中显示5列。之后,它将从新行开始。请帮忙 在第一个值中添加Php 引导和codeIgniter数据显示在表中,php,twitter-bootstrap-3,foreach,html-table,codeigniter-3,Php,Twitter Bootstrap 3,Foreach,Html Table,Codeigniter 3,我正在从数据库中提取数据。我想在表中显示该数据,但我想在一行中显示5列。之后,它将从新行开始。请帮忙 在第一个值中添加,在第五个值中添加。它将运行 <table class="table table-bordered table-hover"> <?php foreach ($pin_data as $pin) { ?> <tr> <td><?php echo $pin->locatio
<table class="table table-bordered table-hover">
<?php foreach ($pin_data as $pin) {
?>
<tr>
<td><?php echo $pin->location;?> <?php echo $pin->pincode;?></td>
</tr>
<?php
} ?>
</table>
希望这将帮助您:
这样做:
您可以使用模数运算符和计数器:
<table class="table table-bordered table-hover">
<?php foreach ($pin_data as $pin) { ?>
<tr>
/*change your column name as according to you*/
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
</tr>
<?php } ?>
</table>
再读一遍我的问题。
<table class="table table-bordered table-hover">
<?php foreach ($pin_data as $pin) { ?>
<tr>
/*change your column name as according to you*/
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
<td><?php echo $pin->pincode;?></td>
<td><?php echo $pin->location;?></td>
</tr>
<?php } ?>
</table>
<table class="table table-bordered table-hover">
<tr> <!-- start initial row -->
<? $counter = 1;
foreach ($pin_data as $pin):?>
<td>
<?= $pin->location;?> <?= $pin->pincode;?>
</td>
<?if($counter % 5 == 0):?> //if $counter is a multiple of 5, close the current row and start an new one
</tr>
<tr>
<?endif;?>
<? $counter++;?>
<?endforeach;?>
</table>