mo_ib_bmw Posted August 23, 2009 Share Posted August 23, 2009 hi,i want to divide the result from mysql databases by PhPi want to do the result as this picturei'm trying to do it but i have some error..my code <?echo "<table><tr>";$sql=mysql_query("select*from tblname order by id desc");while($rows=mysql_fetch_array($sql)) {echo "<td><table><tr><td>";echo $rows['name'];echo "</td></tr></table></td>";$i=1;$i++;}if($i == 3){echo "</tr><tr>";}else {}echo "</table>"; but this code Don't Run..! i hope u help me... Link to comment Share on other sites More sharing options...
Ingolme Posted August 23, 2009 Share Posted August 23, 2009 Your code doesn't work because you keep resetting $i to 1 on every single iteration.What's with all those one-cell tables? A table with a single cell is nothing more than a box, and a much more efficient way to make a box is with a <div> element.Try this: <?php$sql = mysql_query("select * from tblname order by id desc");while($rows=mysql_fetch_array($sql)) { echo '<div class="box">' . $rows['name'] . '</div>';}?> And then you can get this CSS to organize your boxes three on each line. .box { width: 33%; } Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted August 23, 2009 Author Share Posted August 23, 2009 thanx Ingolme,nice way you do but don't write how can identify 3 result and do <br> automatic by Php... Link to comment Share on other sites More sharing options...
Ingolme Posted August 23, 2009 Share Posted August 23, 2009 thanx Ingolme,nice way you do but don't write how can identify 3 result and do <br> automatic by Php...The CSS I used takes care of that, but if you really want to do something for every third row, use a modulus operator.Here's an example of how it works in a normal loop:$i = 0;while($i < 20) { echo $i . ' '; if($i%3 == 2) { echo "<br>" }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.