mkosmosports Posted January 9, 2007 Share Posted January 9, 2007 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 More sharing options...
effigy Posted January 9, 2007 Share Posted January 9, 2007 Set up a counter and use [url=http://us3.php.net/manual/en/language.operators.arithmetic.php]modulus[/url].[code]if ($counter % 5 == 0) { echo '---'; }[/code] Link to comment https://forums.phpfreaks.com/topic/33460-inserting-a-line-break-if-count-is-5/#findComment-156646 Share on other sites More sharing options...
emehrkay Posted January 9, 2007 Share Posted January 9, 2007 place this before the loop$count = 0;then inside the loop do this[code]<?phpif (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] Link to comment https://forums.phpfreaks.com/topic/33460-inserting-a-line-break-if-count-is-5/#findComment-156652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.