darktiger Posted February 26, 2006 Share Posted February 26, 2006 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 More sharing options...
Hokus Posted February 26, 2006 Share Posted February 26, 2006 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] Link to comment https://forums.phpfreaks.com/topic/3646-mysql-db-multi-colrow-table/#findComment-12648 Share on other sites More sharing options...
darktiger Posted February 27, 2006 Author Share Posted February 27, 2006 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] Link to comment https://forums.phpfreaks.com/topic/3646-mysql-db-multi-colrow-table/#findComment-12658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.