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

<table class="table">
      <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>
        <?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;?>

Updated 5-Aug-21 22:52pm
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 foreach ($result as $file): ?>
            <dd><?php echo $file['id']; ?></dd>
            <dd><?php echo $file['title']; ?></dd>
            <dd><?php echo $file['grade']; ?></dd>
            <dt>Notice Date</dt>
            <dd><?php echo $file['date']; ?></dd>
            <dd><a href="admin/uploads/School/admissionform/<?php echo $file['name']; ?>">...</a></dd>
<php endforeach;?>
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