Jump to content

loops inside loops.....


mkosmosports

Recommended Posts

Hey,

I have this loop:
    foreach($result3arr as $value)
    {
    $tname = $value['quickname'];
    $tid = $value['teamid'];
    $sdate = $value['sdate'];
    if($sdate > "$seasonbeg-07-01" && $sdate < "$seasonbeg-07-20")
    {
    echo("<div class=\"teamlist\"><a href=\"mainstats.html?l=2&team=$tid\" alt=\"\">$tname</a></div>");
    }
    else if($sdate > "$seasonbeg-09-01" && $sdate < "$seasonbeg-09-20")
    {
    echo("<div class=\"teamlist\"><a href=\"mainstats.html?l=2&team=$tid\" alt=\"\">$tname</a></div>");
    }
    }

What I would want to do is put the echos inside the condition in certain html tags, but those tages should only appear once per condition, so something like
                        echo("<div>"); <---this needs to run only once though
    if($sdate > "$seasonbeg-07-01" && $sdate < "$seasonbeg-07-20")
    {
    echo("<div class=\"teamlist\"><a href=\"mainstats.html?l=2&team=$tid\" alt=\"\">$tname</a></div>");
    }
                        echo("</div>"); <---this needs to run only once though

Is this even possible?

Any help appreciated!
Link to comment
https://forums.phpfreaks.com/topic/35305-loops-inside-loops/
Share on other sites

:)..I know it doesnt "need" to stay inside the loop, but Id like it too. Id just want to put the echos in the condition in div tags that only appear once.

What Im trying to avoid is writing multiple foreach loops. I wanna write just one...

I guess its impossible though. I was thinking there might be some kind of array function....
Link to comment
https://forums.phpfreaks.com/topic/35305-loops-inside-loops/#findComment-166887
Share on other sites

Damn, looks like I confused you guys a little....:P...my apologies...
echo("<div class=\"teamlistcupcontainer\">");
    foreach($result3arr as $value)
    {
    $tname = $value['quickname'];
$tallowed = $value['linkable'];
    $tid = $value['teamid'];
    $sdate = $value['sdate'];
    if($sdate > "$seasonbeg-07-21" && $sdate < "$seasonbeg-08-01")
    {
    echo("<div class=\"teamlist\"><a href=\"mainstats.html?l=2&team=$tid\" alt=\"\">$tname</a></div>");
    }
echo("</div>");

The above loop contains an if condition and the results of it are inside div class teamlistcupcontainer. I have 3 more conditions to write for this loop, and I need them to also be inside div class teamlistcupcontainer. Logically, I would need to write 3 more foreach loops, but Im asking if this is something I can avoid this somehow....
Link to comment
https://forums.phpfreaks.com/topic/35305-loops-inside-loops/#findComment-166892
Share on other sites

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.