Click here to Skip to main content
15,063,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to display database data in table format but I'm having issue in formatting to display data in table it's not displaying in correct order. I want to display data vertically but it's displaying horizontally.

What I have tried:

I have tried this

HTML
<table class="table">
  <thead>
    <tr>
      <th scope="col">S.N.</th>
      <th scope="col">Title</th>
      <th scope="col">Grade</th>
      <th scope="col">Notice Date</th>
      <th scope="col">Actions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <?php foreach ($result as $file): ?>
      <th scope="row"><?php echo $file['id']; ?><br/></th>
      <td><?php echo $file['title']; ?><br/></td>
      <td><?php echo $file['grade']; ?><br/></td>
      <td><?php echo $file['date']; ?><br/></td>
      <td><a href="admin/uploads/School/admissionform/<?php echo $file['name']; ?>"></a><br/></td>
        <?php endforeach;?>

    </tr>
    
  </tbody>
</table>  

https://i.stack.imgur.com/KOPAe.png[^]
Posted
Updated 5-Aug-21 22:52pm
v2
Comments
Gerry Schmitz 5-Aug-21 17:27pm
   
Sounds like you need to "pivot".

1 solution

You are displaying each record in a single row in a table. Table rows are displayed horizontally.

If you want to display the records vertically, change the markup you are generating. For example:
PHP
<ul>
<?php foreach ($result as $file): ?>
    <li>
        <dl>
            <dt>S.N.</dt>
            <dd><?php echo $file['id']; ?></dd>
            <dt>Title</dt>
            <dd><?php echo $file['title']; ?></dd>
            <dt>Grade</dt>
            <dd><?php echo $file['grade']; ?></dd>
            <dt>Notice Date</dt>
            <dd><?php echo $file['date']; ?></dd>
            <dt>Actions</dt>
            <dd><a href="admin/uploads/School/admissionform/<?php echo $file['name']; ?>">...</a></dd>
        </dl>
    </li>
<php endforeach;?>
</ul>
Then use CSS to style the list to make it look like what you want.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900