Log in

View Full Version : Split Search results into columns



e1seix
07-15-2007, 09:34 PM
For example, if i were to call a search from mysql database that's particularly long, what php code could i use to split the results into, say, three separate columns within a single table, without repetition ie. i don't want the "if" statement to just repeat itself three times

Twey
07-15-2007, 10:11 PM
Hmm...
<table>
<tr>
<?php for($i = 0; $row = mysql_fetch_array($rs); ++$i) { ?>
<?php if($i &#37; 3 === 0) { ?>
</tr>
<tr>
<?php } ?>
<td>
<?php echo($row['data']); ?>
</td>
<?php } ?>
</tr>
</table>You get an extra row at the beginning and end of the table, but it's as neat as I can make it, I think. You could, of course, take care of the extra rows with another two if blocks.