Jump to content

hchsk

Members
  • Posts

    110
  • Joined

  • Last visited

    Never

Everything posted by hchsk

  1. 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.
  2. 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 )
  3. 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]; ?>
  4. 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; ?>
  5. 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.
  6. 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
  7. how can i check the number of occurrences of an ampersand (&) in a string? count_chars seems to be what i'm looking for, but it returns an array that to be honest i dont entirely understand, i want an integer return perhaps somehow with regex?
  8. nevermind! success! thanks so much
  9. thanks, but i still only get: Team 12 with x points with x points
  10. 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
×
×
  • 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.