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.
auto-breaking to new line
Moderator: General Moderators
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.
}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:
I don't quite understand Zoxive's solution, either.
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>";
}