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
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Thu Feb 04, 2010 5:34 pm
How do I add '<br />' after every six rows?
Code: Select all
while($f = mysql_fetch_array($q)) { }
manohoo
Forum Contributor
Posts: 201 Joined: Wed Dec 23, 2009 12:28 pm
Post
by manohoo » Thu Feb 04, 2010 6:28 pm
Something like this could work:
Code: Select all
$q = "SELECT field FROM table";
$result = mysql_query($q);
$breakRows = 6;
$i = 0; //counter
while($row = mysql_fetch_array($result)){
echo $row['field'];
if (($i % $breakRows) == 0) {echo "<br />";}
$i++;
}
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Fri Feb 05, 2010 3:20 pm
Hmm.. $breakRows = 5; $total_rows = 10;, but it adds a <br /> after row1 and row6.
xjake88x
Forum Commoner
Posts: 50 Joined: Sun Aug 01, 2004 7:05 pm
Post
by xjake88x » Fri Feb 05, 2010 3:22 pm
Set the i to 1 first.