Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在表格中排列数据?_Html_Codeigniter_Foreach_Html Table_Codeigniter 3 - Fatal编程技术网

Html 在表格中排列数据?

Html 在表格中排列数据?,html,codeigniter,foreach,html-table,codeigniter-3,Html,Codeigniter,Foreach,Html Table,Codeigniter 3,我从数据库中检索数据并尝试在表中实现它们,但现在我不知道如何在表中排列它们。我的看法是: <?php include('inc/header.php');?> <div class="main"> <table> <thead> <tr>ID:</tr> <th>Name:</th> </thead> <tbody&g

我从数据库中检索数据并尝试在表中实现它们,但现在我不知道如何在表中排列它们。我的看法是:

<?php include('inc/header.php');?>

<div class="main">

<table>

    <thead>
            <tr>ID:</tr>
            <th>Name:</th>

</thead>

<tbody>
<tr>

        <?php foreach ($view as $row) :?>

            <?php $i = 1;?>
            <?php echo "<td>".$row->audio."</td>";?>
            <?php echo $i++;?>
            <?php endforeach;?>


    </tr>
</tbody>

</table>


</div>
<?php include('inc/footer.php');?>

身份证件:
姓名:
我只想将place id从一个增加到尽可能多的记录,并将它们排列到一个表中。

您可以试试这个

<?php $i = 1;?>
<?php foreach ($view as $row) :?>
<tr>
            <?php echo "<td>".$i++."</td>";?>
            <?php echo "<td>".$row->audio."</td>";?>

 </tr>
<?php endforeach;?>

您的foreach循环应该是这样的

<tbody>
    <?php 
    $i = 1;
    foreach ($view as $row)
    {
        echo "<tr>";
        echo "<td>".$i."</td>";
        echo "<td>".$row->audio."</td>";
        $i++;
        echo "</tr>";
    }
   ?>
</tbody>

应该是

<thead>
    <tr>
        <th>ID:</th>
        <th>Name:</th>
    </tr>
</thead>

身份证件:
姓名:

试试这个代码

  <?php
  $i=1;
  foreach ($view as $row) 
  {

 ?>
    <tr>
        <td><?php echo $i; ?></td>
        <td><?php echo $row->audio;?></td>        
     </tr>
    <?php 
    $i++;
    } ?>

请尝试以下代码:

<?php
  $i=0;//place the initial value outside the loop
  foreach ($view as $row) 
  {
  $i++;//increment the value
 ?>
    <tr>
        <td><?php echo $i;//display the value ?></td>
        <td><?php echo $row->audio;?></td>        
     </tr>
    <?php 

    } ?>


因为id丢失了,所以我很高兴。我对表头的声明是正确的,因为id在名称上方@spartan@sudeepacharya它应该是
而不是
@sudeepacharya立即检查编辑。现在可能清楚了吧