mkosmosports Posted January 23, 2007 Share Posted January 23, 2007 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 thoughIs this even possible?Any help appreciated! Quote Link to comment Share on other sites More sharing options...
Jenk Posted January 23, 2007 Share Posted January 23, 2007 umm.. just echo it outside of the loop..[code]<?phpecho "<div>\n";foreach (/* ... */){ // etc}echo "</div>\n";?>[/code] Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 23, 2007 Author Share Posted January 23, 2007 The thing is though, it needs to stay inside the foreach loop. Except I want it to only run once... Quote Link to comment Share on other sites More sharing options...
Jenk Posted January 23, 2007 Share Posted January 23, 2007 No, it doesn't need to stay inside the loop. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2007 Share Posted January 23, 2007 lol that's logically impossible. It doesn't need to, what Jenk posted is right. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 23, 2007 Author Share Posted January 23, 2007 :)..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.... Quote Link to comment Share on other sites More sharing options...
Jenk Posted January 23, 2007 Share Posted January 23, 2007 you still only have one foreach. The echo's are simply outside the loop. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 23, 2007 Author Share Posted January 23, 2007 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.... Quote Link to comment Share on other sites More sharing options...
Jenk Posted January 23, 2007 Share Posted January 23, 2007 If they need to be in seperate div's, they need to be in seperate loops. If they need to be in the same div's, they need to be in the same loop. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 23, 2007 Author Share Posted January 23, 2007 Ok, fair enough. That makes sense. Thanks Jenk and Jesirose! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.