Page 1 of 1

auto-breaking to new line

Posted: Mon Dec 03, 2007 12:13 pm
by Faithe
I have a while function where it calls all the results from a database where the id is from a GET id.
The results are set up in a table so that it just creates one big line across the screen.
What I would like to happen is where once it hits four results, it breaks to a new line,
all the way down until there are no more results.

Can anyone advise me in the right direction? I've been trying for a few days now, but I can't seem to get it :]
Thanks a lot.

Posted: Mon Dec 03, 2007 12:21 pm
by feyd
Have a read through the first and second threads linked from Useful Posts.

Posted: Mon Dec 03, 2007 12:22 pm
by Zoxive

Code: Select all

$i=1;
while( /* while loop */ ){
  /* Other code here */
  if($i++ % 4 == 0) echo '<br/>'; // Or how ever you want to line break.
}

Posted: Mon Dec 03, 2007 2:19 pm
by Faithe
I read through the posts on the Useful Posts page, but I actually had a bit of trouble understanding the solution to it :]

If you could help me understand, that would great.
Here's what I have so far:

Code: Select all

$teacher = mysql_query("SELECT * FROM teachers WHERE dep = 'math' OR altdep = 'math' ORDER  BY name");
$i=1;
while ($results1 = mysql_fetch_array($teacher)) {
echo "<td align=center valign=top><center><a href=teacher.php?id=";
echo $results1['id'];
echo ">";
echo "<img src=pictures/".$results1['id'].".jpg border=0 width=110 height=157><br>";
echo $results1['name'];
echo "</a></td>";
if($i++ % 4 == 0) echo "<br>";
}
I don't quite understand Zoxive's solution, either.

Posted: Mon Dec 03, 2007 2:34 pm
by Faithe
Nevermind, I messed around a bit and got it to work :]

Thank you both!