Jump to content

How To Divide The Result From Mysql By Php


mo_ib_bmw
 Share

Recommended Posts

hi,i want to divide the result from mysql databases by PhPi want to do the result as this picture128377273.jpgi'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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...