tags:

views:

36

answers:

2

Using php to get results from a database using

$exe = mysql_query("SELECT * FROM info ORDER BY ID ASC");

echo 'table width="80%"';

while ($r = mysql_fetch_array($exe)) {

Then the table layout. So I am just getting a long long list of results. Is there anyway to after every 10 results make a break or put a line across?

+5  A: 

Use a counter and the modulus operator to put something every 10 rows:

$i = 0;
while (($row = mysql_fetch_array($exe)) != null) {
  // print the row
  if (++$i % 10 == 0) {
    echo '<tr><td><hr></td></tr>';
  }
}
cletus
There is no need for the != null, null is a falsy value in PHP so when $row == null the while loop will break.
Pim Jager
A: 

You can use modulus.

silent