...

View Full Version : structuring a table in a while loop



Jacobb123
07-22-2008, 10:27 PM
I have the following code that needs to be lined up sid by side like below:

3 3 3
3 3 3
3 3 3

I can't seem to figure out how to get it done

Here is the code:


<?PHP
$query = mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
$i=0;
while($row = mysql_fetch_array($query)){
?>

<table border="1" width = "100">
<tr>
<th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
</tr>
<tr>
<td><?php echo $row['name']; ?></td>
</tr>
<tr>
<td><?php echo $row['desc']; ?></td>
</tr>
</table>

<? $i++; }

?>

masterofollies
07-23-2008, 12:55 AM
You need to take the table outside of the while loop. Do it like this. Copy this


<?PHP
$query = mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
$i=0;
<table border="1" width = "100">
while($row = mysql_fetch_array($query)){
?>


<tr>
<th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
</tr>
<tr>
<td><?php echo $row['name']; ?></td>
</tr>
<tr>
<td><?php echo $row['desc']; ?></td>
</tr>


<? $i++; }
</table>

?>

Jacobb123
07-23-2008, 08:51 AM
That still does not work. It still gives me the pattern

1
1
1
1
1
1
1

This need to be

3 3 3
3 3 3
3 3 3

anyone

oesxyl
07-23-2008, 09:09 AM
use mysql_fetch_assoc instead of mysql_fetch_array.

regards

dumpfi
07-23-2008, 02:15 PM
<?PHP
$query = mysql_query("Select * from franks_puzzles") or trigger_error(mysql_error());
$i=0;
echo '<table border="1" width = "100">';
while($row = mysql_fetch_assoc($query)){
?>
<tr>
<th scope="col"><img src="images/<?php echo $row['image']; ?>" width ="100" ></th>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['desc']; ?></td>
</tr>
<?php $i++; }
echo '</table>';
?> dumpfi

masterofollies
07-23-2008, 02:54 PM
Ah yeah there was too many <tr> tags. <tr> means to break a line down. Where <td> means to be side by side. So you only need 1 <tr> opening and closing tag.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum