Jump to content

inserting a line break if </div> count is 5...


mkosmosports

Recommended Posts

Hey,

I have this line of code here which outputs all of the months covered in a given year.
foreach ($transferdate as $trdate)
{
if (substr("$trdate",0,4) == "$season")
{
$trmon = substr("$trdate",4);
echo("<div class=\"transfermon\"><a href=\"players.html?view=transfers&season=$season&in=$trmon\" alt=\"\">$trmon/$season</a></div>");
}
}

This works perfectly, theres just one thing that I cant seem to figure out. I want php to insert a <br> tag as soon as there is a fifth </div> tag present in the loop results.

Any help appreciated...
Link to comment
https://forums.phpfreaks.com/topic/33460-inserting-a-line-break-if-count-is-5/
Share on other sites

place this before the loop
$count = 0;

then inside the loop do this
[code]
<?php
if (substr("$trdate",0,4) == "$season"){
$break = (++$count % 5) ? '<br />' : ""
$trmon = substr("$trdate",4);
      echo("<div class=\"transfermon\"><a href=\"players.html?view=transfers&season=$season&in=$trmon\" alt=\"\">$trmon/$season[/url]</div>".$break);
?>
[/code][/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.