hchsk Posted May 6, 2009 Share Posted May 6, 2009 can anyone help me find my problem? print_r($rank) == Array ( [12] => 1st place [11] => 2nd place [9] => 3rd place [5] => 4th place [7] => tied for 5th place [6] => tied for 5th place [4] => 7th place [2] => unranked [3] => unranked [10] => unranked [1] => unranked [8] => unranked [0] => th place [13] => unranked ) foreach ($rank as $team => $string) { if (strpos($rank[$team], '1<sup>st</sup>')) { if ($firstplace == '') { $firstplace = "Team $team <br>" ; } else { $firstplace = "$firstplace & Team $team <br>" ; }} if (strpos($rank[$team], '2<sup>nd</sup>')) { if ($secondplace == '') { $secondplace = "Team $team <br>" ; } else { $secondplace = "$secondplace & Team $team <br>" ; } } } $firstplace = "$firstplace with <b>x</b> points <br>"; $secondplace = "$secondplace with <b>x</b> points <br>"; gives: with x points with x points thanks for your time and help Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/ Share on other sites More sharing options...
ratcateme Posted May 6, 2009 Share Posted May 6, 2009 strpos is returning 0 php treats a 0 as false. try changing the ifs to if (strpos($rank[$team], '1<sup>st</sup>') !== false) { and if (strpos($rank[$team], '2<sup>nd</sup>') !== false) { !== checks the type of value as well. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827101 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 thanks, but i still only get: Team 12 with x points with x points Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827103 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 nevermind! success! thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827106 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 well, i thought that did it, but now it's not printing the double values, im very confused, i dont see a flaw in the logic ive used: // ------------------------- SET CONTENTS foreach ($rank as $team => $string) { if (strpos($rank[$team], '1<sup>st</sup>')!== false) { if ($firstplace == '') { $firstplace = "Team $team <br>" ; $pointsfirst = $scores[$team-1]; } else { $firstplace = "$firstplace & Team $team <br>" ; }} if (strpos($rank[$team], '2<sup>nd</sup>')!== false) { if ($secondplace == '') { $secondplace = "Team $team <br>" ; $pointssecond = $scores[$team-1];} else { $secondplace = "$secondplace & Team $team <br>" ; }} if (strpos($rank[$team], '3<sup>rd</sup>')!== false) { if ($thirdplace == '') { $thirdplace = "Team $team <br>" ; $pointsthird = $scores[$team-1]; } else { $thirdplace = "$thirdplace & Team $team <br>" ; }} } $firstplace = "$firstplace with <b>$pointsfirst</b> points <br>"; $secondplace = "$secondplace with <b>$pointssecond</b> points <br>"; $thirdplace = "$thirdplace with <b>$pointsthird</b> points <br>"; print $firstplace . '<br>' . $secondplace . '<br>' . $thirdplace; gets: with points with points Team 9 with 5 points Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827152 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Does $rank[$team] have those <sup> and </sup> tags in them? Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827158 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 yes Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827161 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 hmm, removing the <sup> tags make the function work for the first place, but changes nothing with the second. it is interesting, that the tags do not appear in the array, but when $rank[$team] is printed to the webpage, the ordinals are raised. Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827162 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 or, if someone might be better able to help me fix the script i wrote before, but formatted for 10 teams, and i now need to include 12, but when i thought i changed all i needed to, it malfunctioned. i was trying to rewrite a shorter version anyway, using rankings instead of checking the scores itself <?php $filename = "scorestore.txt"; $score = file($filename); for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {$score[$counter] = intval($score[$counter]); } function doublemax($mylist){ $maxvalue=max($mylist); while(list($key,$value)=each($mylist)){ if($value==$maxvalue)$maxindex=$key; } return array("m"=>$maxvalue,"i"=>$maxindex += 1); } // ------------------------- GET RID OF ELIMINATED TEAMS $filename = "deathcount.txt"; $deathcount = file($filename); $deathcountarray = str_split($deathcount[0]); for ( $counter = 0; $counter <= 12; $counter += 1 ) { if ($deathcountarray[$counter] == 6) {$score[$counter] = 0;} } // ------------------------- first place!! $first = doublemax($score); // ------------------------- THREE WAY TIE? for ( $counter = 0; $counter <= 12; $counter += 1 ) {if ($score[$counter] == $first[m]) {$hold += 1;}} if ($hold==3) {$triptie = 1;} else {$triptie = 0;} // ------------------------- CHECK FOR TIE if($triptie == 1){$place = ' first,<br>second & third';} else {$place = ' first<br>& second';} for ( $counter = 0; $counter <= 12; $counter += 1 ) {if ($score[$counter] == $first[m]) {if ($tie == '') {$tie = ' <div style="background-color: #b10961;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for' . $place . '!</b><br><br></div>'; $tiet2 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else {$tiet2 = $tiet2 . '<br> & Team ' . ($counter+=1);$which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie = ''; $tiet2 = '';} // ------------------------- second place!! $score[($first[i]-=1)] = 0; $second = doublemax($score); // ------------------------- CHECK FOR TIE if($tie == ''){$place = ' second<br>& third';} else {$place = ' third';} for ( $counter = 0; $counter <= 12; $counter += 1 ) {if ($score[$counter] == $second[m]) {if ($tie2 == '') {$tie2 = ' <div style="background-color: #B15E89;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for' . $place . '!</b><br><br></div>'; $tiet3 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else {$which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie2 = ''; $tiet3 = '';} // ------------------------- third place!! $score[($second[i]-=1)] = 0; $third = doublemax($score); // ------------------------- CHECK FOR TIE for ( $counter = 0; $counter <= 12; $counter += 1 ) {if ($score[$counter] == $third[m]) {if ($tie3 == '') {$tie3 = ' <div style="background-color: #FE86C4;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for third!</b><br><br></div>'; $tiet4 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else { if ( ($counter+=1) != $third[i] ) { $tiet4 = $tiet4 . '<br> & Team ' . (($counter+=1)-1);} $which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie3 = ''; $tiet4 = '';} // who knows why, but it works $first[i] += 1; $second[i] += 1; echo <<<END <div id=RANKING style="float:left;margin:10px;margin-top:-80;border-left:#b10961 solid 1px;width:110px;text-align:right;padding-right:10px;height:350px;"> <div style="color:purple;font-size:14;font-weight:bold;padding:5px;"> LEADING: </div> END; if ($first[m] == 0) { echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;"> <i>No scores yet.</i><br> </div> END; } if ($first[m] != 0) { echo $tie; if ($tie == '') { echo <<<END <div style="background-color: #b10961;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>First place!</b><br> </div> END; } echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $first[i] $tiet2 <br> <i>with <b>$first[m]</b> points</i><br> </div> END; } if (($second[m] != 0) && ($triptie != 1)) { echo $tie2; if ($tie2 == '') {echo <<<END <div style="background-color: #B15E89;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"><b> END; if ($tie == '') {$place = 'Second place!';} else {$place = 'Third place!';} echo $place.'</b><br></div>'; } echo <<<END <div style="background-color: #f8f8f8;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $second[i] $tiet3 <br> <i>with <b>$second[m]</b> points</i><br> </div> END; } if (($third[m] != 0) && ($tie == '') && ($tie2 == '')) { echo $tie3; if ($tie3 == '') {echo <<<END <div style="background-color: #FE86C4;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>Third place!</b><br> </div> END; } echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $third[i] $tiet4 <br> <i>with <b>$third[m]</b> points</i><br> </div> END; } echo <<<END <br> <script type="text/javascript" src="scripts/clock.js"></script><div id="clockbox"></div> </div> END; ?> Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827174 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 $placements = array( 'first' => array(), 'second' => array(), 'third' => array() ); foreach ($rank as $team => $place) { if (strpos($place, '1st') !== false) $placements['first'][] = $team; else if (strpos($place, '2nd') !== false) $placements['second'][] = $team; else if (strpos($place, '3rd') !== false) $placements['third'][] = $team; } foreach ($placements as $placement => $teams) { $teams_count = count($teams); if ($teams_count == 0) echo 'No teams in ' . $placement . '. <br />'; else if ($teams_count == 1) echo 'Team ' . $teams[1] . ' in ' . $placement . ' with x points. <br />'; else echo 'Teams ' . implode(', ', $teams) . ' are tied for ' . $placement . ' with x points. <br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827226 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 thanks! that did exactly what i asked for, and actually a little bit more, that i'm afraid i shouldv mentioned. the format i was using myself is important for the display i need to place it in, and the whole function gets more complicated i'll post the function i was using previously, but for 10 teams, and i now need it to work for 12, (and any that need to get added in the future) without problems <?php include("ranketc.php"); $filename = "scorestore.txt"; $score = file($filename); $first = ''; $second = ''; $third = ''; $fourth = ''; $tie = ''; $tie2 = ''; $tie3 = ''; $tie4 = ''; $which = ''; $nteams = count($score); for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {$score[$counter] = intval($score[$counter]); } function doublemax($mylist){ $maxvalue=max($mylist); while(list($key,$value)=each($mylist)){ if($value==$maxvalue)$maxindex=$key; } return array("m"=>$maxvalue,"i"=>$maxindex += 1); } // ------------------------- GET RID OF ELIMINATED TEAMS $filename = "deathcount.txt"; $deathcount = file($filename); $deathcountarray = str_split($deathcount[0]); for ( $counter = 0; $counter <= $nteams; $counter += 1 ) { if ($deathcountarray[$counter] == 6) {$score[$counter] = 0;} } // ------------------------- first place!! $first = doublemax($score); // ------------------------- THREE WAY TIE? for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {if ($score[$counter] == $first[m]) {$hold += 1;}} if ($hold==3) {$triptie = 1;} else {$triptie = 0;} // ------------------------- CHECK FOR TIE if($triptie == 1){$place = ' first,<br>second & third';} else {$place = ' first<br>& second';} for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {if ($score[$counter] == $first[m]) {if ($tie == '') {$tie = ' <div style="background-color: #b10961;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for' . $place . '!</b><br><br></div>'; $tiet2 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else {$tiet2 = $tiet2 . '<br> & Team ' . ($counter+=1);$which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie = ''; $tiet2 = '';} // ------------------------- second place!! $score[($first[i]-=1)] = 0; $second = doublemax($score); // ------------------------- CHECK FOR TIE if($tie == ''){$place = ' second<br>& third';} else {$place = ' third';} for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {if ($score[$counter] == $second[m]) {if ($tie2 == '') {$tie2 = ' <div style="background-color: #B15E89;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for' . $place . '!</b><br><br></div>'; $tiet3 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else {$which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie2 = ''; $tiet3 = '';} // ------------------------- third place!! $score[($second[i]-=1)] = 0; $third = doublemax($score); // ------------------------- CHECK FOR TIE for ( $counter = 0; $counter <= $nteams; $counter += 1 ) {if ($score[$counter] == $third[m]) {if ($tie3 == '') {$tie3 = ' <div style="background-color: #FE86C4;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding-left:5px;"> <b>TIED for third!</b><br><br></div>'; $tiet4 = '<br> & Team ' . ($counter+=1); $hold = $counter -=1; $which = 1;} else { if ( ($counter+=1) != $third[i] ) { $tiet4 = $tiet4 . '<br> & Team ' . (($counter+=1)-1);} $which = false; $score[$hold] = 0;} } } if ($which == 1) {$tie3 = ''; $tiet4 = '';} // who knows why, but it works $first[i] += 1; $second[i] += 1; echo <<<END <div id=RANKING style="float:left;margin:10px;margin-top:-80;border-left:#b10961 solid 1px;width:110px;text-align:right;padding-right:10px;height:350px;"> <div style="color:purple;font-size:14;font-weight:bold;padding:5px;"> LEADING: </div> END; if ($first[m] == 0) { echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;"> <i>No scores yet.</i><br> </div> END; } if ($first[m] != 0) { echo $tie; if ($tie == '') { echo <<<END <div style="background-color: #b10961;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>First place!</b><br> </div> END; } echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $first[i] $tiet2 <br> <i>with <b>$first[m]</b> points</i><br> </div> END; } if (($second[m] != 0) && ($triptie != 1)) { echo $tie2; if ($tie2 == '') {echo <<<END <div style="background-color: #B15E89;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"><b> END; if ($tie == '') {$place = 'Second place!';} else {$place = 'Third place!';} echo $place.'</b><br></div>'; } echo <<<END <div style="background-color: #f8f8f8;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $second[i] $tiet3 <br> <i>with <b>$second[m]</b> points</i><br> </div> END; } if (($third[m] != 0) && ($tie == '') && ($tie2 == '')) { echo $tie3; if ($tie3 == '') {echo <<<END <div style="background-color: #FE86C4;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>Third place!</b><br> </div> END; } echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $third[i] $tiet4 <br> <i>with <b>$third[m]</b> points</i><br> </div> END; } echo <<<END <br> <script type="text/javascript" src="scripts/clock.js"></script><div id="clockbox"></div> </div> END; ?> and here is the function you gave me, but modified, and with some added to it that will not seem to function: <?php include("ranketc.php"); $placements = array( 'first' => array(), 'second' => array(), 'third' => array() ); foreach ($rank as $team => $place) { if (strpos($place, '1st') !== false) $placements['first'][] = $team; else if (strpos($place, '2nd') !== false) $placements['second'][] = $team; else if (strpos($place, '3rd') !== false) $placements['third'][] = $team; } foreach ($placements['first'] as $counter => $team) { $placements[$counter] = "Team $team"; } for($cntr=0;$cntr<count($placements['first']);$cntr++) { if ($cntr!==0){$displayfirst = $displayfirst . '<br>& Team ' . $placements['first'][$cntr];} else {$displayfirst = 'Team ' . $placements['first'][$cntr];} } $displayfirst = $displayfirst . "<br><i>with <b>" . $scores[$placements['first'][$cntr]] . "</b> points</i>"; for($cntr=0;$cntr<count($placements['second']);$cntr++) { if ($cntr!==0){$displaysecond = $displaysecond . '<br>& Team ' . $placements['second'][$cntr];} else {$displaysecond = 'Team ' . $placements['second'][$cntr];} } $displaysecond = $displaysecond . "<br><i>with <b>" . $scores[$placements['second'][$cntr]] . "</b> points</i>";; for($cntr=0;$cntr<count($placements['third']);$cntr++) { if ($cntr!==0){$displaythird = $displaythird . '<br>& Team ' . $placements['third'][$cntr];} else {$displaythird = 'Team ' . $placements['third'][$cntr];} } $displaythird = $displaythird . "<br><i>with <b>" . $scores[$placements['third'][$cntr]] . "</b> points</i>"; print $displayfirst; print '<br><br>'; print $displaysecond; print '<br><br>'; print $displaythird; //print $placements['first'][0] . $placements['first'][1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827994 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Dude, that is a giant mess! I would work on organization. Imagine if you were to calculate for like 9 teams, you'll have a heck of a day. Can you just tell me the format? I rather not read all that. Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-827999 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 yes definitely! haha. i know it's awful, i couldnt for my life figure out how to do it more efficiently, this is basically my first time really using php, and i just figure things out slowly with google. i wrote it before i wrote a full ranking function, which i ended up needing and writing/getting help with later. ok, so here's the goal: echo <<<END <div id=RANKING style="float:left;margin:10px;margin-top:-80;border-left:#b10961 solid 1px;width:110px;text-align:right;padding-right:10px;height:350px;"> <div style="color:purple;font-size:14;font-weight:bold;padding:5px;"> LEADING: </div> END; if (no scores yet) { echo <<<END <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;"> <i>No scores yet.</i><br> </div> END; } if (first place) { echo <<<END <div style="background-color: #b10961;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>First place!</b><br> </div> <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> Team $allfirstplaceteams <br> <i>with <b>$score[oftheseteams]</b> points</i><br> </div> END; } if (2teams or less in firstplace) { echo <<<END <div style="background-color: #B15E89;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"><b> if(twoteamsinfirstplace){$place = 'Third place!';} else {$place = 'Secondplace!'} echo $place.'</b><br></div>'; <div style="background-color: #f8f8f8;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> $allsecondplaceteams <br> <i>with <b>$score[oftheseteams]</b> points</i><br> </div> END; if (oneteaminfirst && oneteaminsecond) { echo <<<END <div style="background-color: #FE86C4;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;color:#ffffff;text-align:left;padding:5px;"> <b>Third place!</b><br> </div> <div style="background-color: #dbd6e1;border-top: 1px solid #ffffff;border-bottom: 1px solid#ffffff;padding-right:5px;padding-bottom:10px;padding-top:5px;"> allteamsinthird <br> <i>with <b>$score[oftheseteams]</b> points</i><br> </div> END; } no matter what: <br> <script type="text/javascript" src="scripts/clock.js"></script><div id="clockbox"></div> </div> a nightmare. thanks for helping here are the arrays i am starting with, and that should be enough to do what i need: $scores (team#-1=>score): Array ( [0] => 0 [1] => 12 [2] => 0 [3] => 7 [4] => 4 [5] => 2 [6] => 2 [7] => 0 [8] => 5 [9] => 7 [10] => 7 [11] => 7 ) $rank (team#=>place): Array ( [2] => 1st place [10] => tied for 2nd place [11] => tied for 2nd place [4] => 2nd place [12] => 2nd place [9] => 6th place [5] => 7th place [6] => tied for 8th place [7] => tied for 8th place [3] => unranked [1] => unranked [8] => unranked [0] => th place [13] => unranked ) Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-828071 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Okay before I start, I'd like to say that I'm not going to be inline-ing any of those CSS. Put them in a CSS class or something. Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-828075 Share on other sites More sharing options...
hchsk Posted May 6, 2009 Author Share Posted May 6, 2009 haha, definitely, thats probably a better idea anyway i suppose, thank you so much for doing this, while i'm delighted, i feel bad that you're handwriting so much just for me, you already have done a lot. i'm glad to help out as much as i can and im very grateful. Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-828079 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Your IF conditions in your examples are confusing. I mean if you think about it, it's stupid. If you have no teams in first, but have some in second, then your arrays are messed up! I hope this is what you want. <?php $output = ''; $placements = array( 'First' => array(), 'Second' => array(), 'Third' => array() ); foreach ($rank as $team => $place) { if (strpos($place, '1st') !== false) $placements['First'][] = $team; else if (strpos($place, '2nd') !== false) $placements['Second'][] = $team; else if (strpos($place, '3rd') !== false) $placements['Third'][] = $team; } foreach ($placements as $placement => $teams) { $teams_count = count($teams); if (empty($teams_count)) continue; $the_score = $score[$teams[0]]; $output .= '<div id="' . $placement . 'place">' . $placement .' place!</div><div id="' . $placement . 'place-teams">'; if ($teams_count == 1) $output .= 'Team ' . $teams[0] . ' <br /> <i>with <strong>' . $the_score . '</strong> ' . ($the_score == 1? 'point' : 'points') . '</i>'; else $output .= 'Teams ' . implode(', ', $teams) . ' <br /> <i>with <strong> ' . $the_score . '</strong> ' . ($the_score == 1? 'point' : 'points') . '</i>'; $output .= '</div>'; } if (empty($output)) $output = '<div id="noscores">No scores yet.</div>'; // style the italics in CSS echo $output; Quote Link to comment https://forums.phpfreaks.com/topic/157013-checking-for-subpos/#findComment-828134 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.