Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/3646-mysql-db-multi-colrow-table/
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]
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.