Click here to Skip to main content
15,120,478 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this code I am displaying posts in three columns. It works well if I have three or more than 3 posts but if I have only one post or two, they spread through out table, Is there any way by which I can restrict a post to take place only meant for it. If I have only one post to display , table should have one post and two empty spaces.

PHP
<table>
<tr>
<?php do { //horizontal looper?>
<td>
<div><h2><?php echo $row['title']; ?></h2></div>          
<div><p><?php echo $row['body']; ?></p></div>
<img src='<?php echo $row['pic']; ?>'>
<div><p><?php echo $row['about']; ?></p></div>
</td>
<?php
$row = $query->fetch(PDO::FETCH_ASSOC);
if (!isset($nested_List)) {
$nested_List= 1;
}
if (isset($row) && is_array($row) && $nested_List++%3==0) {
echo "</tr><tr>";
}
} while ($row); //end horizontal looper 
?>
</table>
Posted
Comments
ZurdoDev 16-Nov-15 7:48am
   
You can put fixed widths on your columns.

1 solution

Use 3 td and put each div into each td. Then use colspan to show 3 td properly. You might need to give width for each td as well

HTML
<table>
<tr>
<td colspan="3/">
</td></tr>
<tr>
<td><div> put your data here</div></td>
<td><div>data></div></td>
<td><div>data</div></td>
</tr>
</table>
   
Comments
Gizmo3 16-Nov-15 10:30am
   
do I need to remove my do while loops? and use code exact in same manner as u did

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