auto-breaking to new line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Faithe
Forum Commoner
Posts: 33
Joined: Tue Jul 12, 2005 3:26 pm
Location: WA

auto-breaking to new line

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have a read through the first and second threads linked from Useful Posts.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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.
}
Faithe
Forum Commoner
Posts: 33
Joined: Tue Jul 12, 2005 3:26 pm
Location: WA

Post 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.
Faithe
Forum Commoner
Posts: 33
Joined: Tue Jul 12, 2005 3:26 pm
Location: WA

Post by Faithe »

Nevermind, I messed around a bit and got it to work :]

Thank you both!
Post Reply