[eluser]mddd[/eluser]
Some pointers:
1. It is better to do your database stuff in the controller or model and use the view only to do output.
2. You could solve the problem by using DIV elements in stead of TD's in a table. If you make the DIVs almost 50% wide and give them float: left; the will nicely follow each other without you having to worry about them being first or second on the row. Basic example of output:
Code:
<div class="itemlist">
<div class="item">Here is your first item</div>
<div class="item">Here is your second item, it could be on the same line</div>
<div class="item">Here is your third item, it could be on a new line</div>
<div class="item">Here is your fourth item</div>
</div>
3. If you want to keep the table structure, you should check after displaying an item to see if its count is odd or even. If it is even, you can put /TD /TR TR TD, if it is odd, just put /TD TD because there will be one more on the line. A basic example:
Code:
<table>
<tr><td>
<?php
$counter=0;
foreach($items as $item)
{
$counter++;
// output your $item here: echo $item->title etc.
if ($counter%2)
{
// it is an odd numbered item, so it will be followed by another on this line
echo '</td><td>';
// was this the last item? then insert a blank item and end the row
if ($counter==sizeof($items)) echo ' </td></tr>';
} else {
// it is an even numbered item, so it will end a line
echo '</td></tr>';
// are there any more items? then start the new line
if ($counter<sizeof($items)) echo '<tr><td>';
}
// ready. end the table
?>
</table>