Jump to content


Photo

MySQL DB > Multi-Col/Row table


  • Please log in to reply
2 replies to this topic

#1 darktiger

darktiger
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 February 2006 - 10:18 PM

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:

<tr>
 <td></td>
 <td></td>
 <td></td>
</tr>
<tr>
 <td></td>
 <td></td>
 <td></td>
</tr>

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

#2 Hokus

Hokus
  • Members
  • PipPip
  • Member
  • 23 posts
  • LocationAlameda, CA, USA

Posted 26 February 2006 - 11:34 PM

You could set up a counter, start a new row and reset it every third count. i.e.

$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>';

[!--sizeo:2--][span style="font-size:10pt;line-height:100%"][!--/sizeo--][!--fonto:Arial--][span style="font-family:Arial"][!--/fonto--][!--coloro:blue--][span style="color:blue"][!--/coloro--]"Experience is a wonderful thing. It enables you to recognize a mistake when you make it again".
[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--][!--fontc--][/span][!--/fontc--]

#3 darktiger

darktiger
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 February 2006 - 02:02 AM

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) View Post[/div][div class=\'quotemain\'][!--quotec--]
You could set up a counter, start a new row and reset it every third count. i.e.

$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>';
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users