sudeep acharya sudeep acharya - 4 months ago 8
HTML Question

Arrange data in tables?

I retrieve the data from the database and tried to implement them in the table. But now i don't know how to arrange them in the table.my view is.

<?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');?>


i just want to make the place id increase from one to the as many records and arrange them into one table.but it is

Answer

Your foreach loop should be like this

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

And <thead> should be

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