03-06-2008, 02:26 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 87
Thanks: 49
|
Best Way To Loop In A Table?
Hi all,
I'm wondering what the best way to loop in a table is? I'm pulling data from a database and want it to display like this:

The only way I know how to do it is by making separate looks for each column like so:
PHP Code:
<table style="float:left;margin:0 15px;"> <?php //Creates a loop that shows all of the data where category = rock $i = 0; $times1 = 4; while ($i < $times1) { $category_artist_rock = mysql_result($rock_result, $i, "cd_artist"); ?> <tr> <td style="font-size:12px;"> <a href="<?php echo $category_artist_rock ?>"><?php echo $category_artist_rock; ?></a> </td> </tr>
<?php $i++; } ?> </table> <table style="float:left;margin:0 15px;"> <?php //Creates a loop that shows all of the data where category = rock $i = 4; $times1 = 8; while ($i < $times1) { $category_artist_rock = mysql_result($rock_result, $i, "cd_artist"); ?> <tr> <td style="font-size:12px;"> <a href="<?php echo $category_artist_rock ?>"><?php echo $category_artist_rock; ?></a> </td> </tr>
<?php $i++; } ?> </table>
Above is the code for displaying two columns with four pieces of table data in each. If I wanted four columns I would have to do this four times. I think this is a very ugly way to do it and is probably using a lot more code than is needed. I know there's a simpler way but I can't think of one.
Thanks in advance,
Steven
|
|
|
|