verdrm Posted March 22, 2008 Share Posted March 22, 2008 How do I echo tables in a grid-like style, maybe 3 or 4 in a row, then break, then 4 more? Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/ Share on other sites More sharing options...
Daniel0 Posted March 22, 2008 Share Posted March 22, 2008 What do you mean. You don't need PHP for that. Anyways, you can do this: <?php echo "<table>"; for ($i = 0; $i <= 10; $i++) { echo "<tr>"; for ($j = 0; $j <= 4; $j++) { echo "<td>test</td>"; } echo "</tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498463 Share on other sites More sharing options...
ohdang888 Posted March 22, 2008 Share Posted March 22, 2008 this is how i do mine... <table> <tr> <?php while($row2 = mysql_fetch_assoc($result)){ if ($x % 3 == 0) {// change the number to number of columns wanted echo '</tr><tr>'; } $x++; echo '<td>'; the info in each colum echo '</td>'; } ?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498494 Share on other sites More sharing options...
marklarah Posted March 23, 2008 Share Posted March 23, 2008 my code: <?php $dn = mysql_query("SELECT * FROM `3`") or die(mysql_error()); echo '<div class="bord"><table width="100%"><tr>'; $i = 0; while ($row = mysql_fetch_array($dn)){ echo '<td><center><a href="?p='.$row['ID'].'"><img src="'.$row['img'].'" width="130" height="105"><br>'.$row['name'].'</center></a></td>'; $i++; if ($i % 3 == 0 ){ echo '</tr><tr><td><hr></td><td><hr></td><td><hr></td></tr><tr>'; // Above there, i just liked hr's, if you dont want them, just change it to this line: echo '</tr><tr>'; } } echo '</tr></table></div>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498524 Share on other sites More sharing options...
verdrm Posted March 23, 2008 Author Share Posted March 23, 2008 I need to arrange the following into a THREE COLUMN PER ROW layout. How would I do that (this code below makes one box)? echo "<table width=\"148\">"; <tr> <td width=\"67\" height=\"67\" align=\"right\"><img src=\"$img\" width=\"67\" height=\"67\" /></td> <td width=\"71\" align=\"center\"><strong><span class=\"large\">$per%</span></strong></td> </tr> <tr> <td height=\"21\" colspan=\"2\" align=\"center\">$response [ $q ]</td> </tr> </table>"; Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498648 Share on other sites More sharing options...
lordfrikk Posted March 23, 2008 Share Posted March 23, 2008 ohdang888 posted answer to your problem. Just adjust it to fit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498655 Share on other sites More sharing options...
marklarah Posted March 23, 2008 Share Posted March 23, 2008 as mine does to. If you want to see mine in action (mods, im not spamming my site, im just showing three colums per row) its http://www.disturbedpickle.com/games.php Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498705 Share on other sites More sharing options...
verdrm Posted March 23, 2008 Author Share Posted March 23, 2008 I do not understand how that script works (I'm new at this). Could someone explain? Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498887 Share on other sites More sharing options...
ohdang888 Posted March 23, 2008 Share Posted March 23, 2008 go to my code above.... ok, so the table obvisouly sets up the grid. The first <table> <tr> <?php while($row2 = mysql_fetch_assoc($result)){ if ($x % 3 == 0) {// The $x++ below keeps track of the amount of columns created. The % calues the remainder when divided by... echo '</tr><tr>';// for example, if $x is 3 (3 columns created so far) then 3 / 3 gives a remiander of 0, so it ends that row, and creates a new one }// after 6,9,12,15, etc. columns are created, the remainder is 0, so a new row is started. $x++; echo '<td>';//This creates a column the info in each colum echo '</td>';//this end the column } ?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-498926 Share on other sites More sharing options...
marklarah Posted March 24, 2008 Share Posted March 24, 2008 Just to clarify, the "%" operator is called a modulus. Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-499104 Share on other sites More sharing options...
verdrm Posted March 24, 2008 Author Share Posted March 24, 2008 Sorry guys, would someone mind taking this and making it into a three column system? Something is throwing me off here; maybe it is the fact that my boxes are actually each complete tables. I need three of these per row...I would really appreciate it if someone could write up the code for this: echo "<table width=\"148\">"; <tr> <td width=\"67\" height=\"67\" align=\"right\"><img src=\"$img\" width=\"67\" height=\"67\" /></td> <td width=\"71\" align=\"center\"><strong><span class=\"large\">$per%</span></strong></td> </tr> <tr> <td height=\"21\" colspan=\"2\" align=\"center\">$response [ $q ]</td> </tr> </table>"; Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-499228 Share on other sites More sharing options...
marklarah Posted March 24, 2008 Share Posted March 24, 2008 <?php $query = mysql_query("SELECT * FROM `foo`") or die(mysql_error()); echo '<table width="148"><tr>'; while ($row = mysql_fetch_array($query)){ echo '<td width="67" height="67" align="right"><img src="'.$row[img].'" width="67" height="67"></td> <td width="71" align="center"><strong><span class="large">'.$row['per'].'</span></strong></td> <td colspan="2" align="center">'.$row['q'].'</td> </tr><tr>'; } echo '</tr></table>'; ?> Is this what you want? Im not quite sure what you want here... Quote Link to comment https://forums.phpfreaks.com/topic/97418-grid/#findComment-499315 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.