Page 1 of 1

Formatting results

Posted: Fri Jul 02, 2004 3:42 am
by CerIs
Say i know how many results im have got from my query, i then want to format them into a table on the page. If want to have 5 columns and i have 17 results back, i want to go along putting each result in a cell till it gets to the end of the row then start a new row. Im not sure how to do this. Ie get it to only print out 2 cells on the last row.

Posted: Fri Jul 02, 2004 7:27 am
by anjanesh

Code: Select all

<?php
$NoOfResults=23;
echo '<TABLE BORDER=1><TR>';

for ($i=1;$i<=$NoOfResults;$i++)
{

 $row=mysql_fetch_array($query);
 echo '<TD>'.$row['whatever'].'</TD>';
 if ($i%5==0)
  echo '</TR><TR>';

}

echo '</TR></TABLE>';
?>

Posted: Fri Jul 02, 2004 8:34 am
by CerIs
:) :) :) That worked !!! Thanks for your help Anjanesh

Posted: Fri Jul 02, 2004 8:40 am
by CerIs
One question though. In ($i%5==0 ) whats the % do ?

Posted: Fri Jul 02, 2004 9:53 am
by pickle
It's the modulus operator.

Posted: Fri Jul 02, 2004 10:00 am
by CerIs
ahhh so its testing to see if theres a remainder: eg 5,10,15 will have no remainder and so start a new row? Thats pretty smart. :o

Posted: Fri Jul 02, 2004 10:00 am
by anjanesh
a%b gives the remainder when a is divided by b