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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.