Jump to content

Archived

This topic is now archived and is closed to further replies.

darktiger

MySQL DB > Multi-Col/Row table

Recommended Posts

Hello,
It has been awhile since I have used PHP, but I am trying to get back into it.

I have a MySQL db with multiple items (duh) and would like to put three items per row on a table so:

[code]
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
[/code]

etc, etc...

Well, I just can't figure out the right steps of while loops, etc to make a row, add three cols of data, and then make a new row...

If someone could give a hint or some pseudo code that would be great. I am not looking for tested code or 100% accurate code - I want to actually put work into this but my mind is drawing a blank and I would prefer to not FTP this file 1000x per minute with me changing things..

Thank you,
Scott

Share this post


Link to post
Share on other sites
You could set up a counter, start a new row and reset it every third count. i.e.

[code]$count = 1;

echo '<tr>';

while( $row = mysql_fetch_array($query) )
{
   echo '<td>'.$row[field].'</td>';
  
   if($count == 3)
   {
      echo '</tr><tr>';
      count = 0;
   }

   $count++;
}

echo '</tr>';[/code]

Share this post


Link to post
Share on other sites
Thank you very much! That worked like a charm - now let me sit down and analyse it...

[!--quoteo(post=349693:date=Feb 26 2006, 06:34 PM:name=Hokus)--][div class=\'quotetop\']QUOTE(Hokus @ Feb 26 2006, 06:34 PM) [snapback]349693[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You could set up a counter, start a new row and reset it every third count. i.e.

[code]$count = 1;

echo '<tr>';

while( $row = mysql_fetch_array($query) )
{
   echo '<td>'.$row[field].'</td>';
  
   if($count == 3)
   {
      echo '</tr><tr>';
      count = 0;
   }

   $count++;
}

echo '</tr>';[/code]
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.