AnAmericanGunner Posted July 14, 2011 Share Posted July 14, 2011 My script currently creates a series of scores based upon criteria. I now need to figure the place (1st - nth) based upon the finalscore variable (which is created by adding the other scores together). I don't know where to begin. For testing, I just echoed the variables out like this: if($classname === "Weanling Young Event Horse" || $classname === "Yearling Young Event Horse" || $classname === "Two Year Old Young Event Horse" || $classname === "Three Year Old Young Event Horse" || $classname === "Four Year Old Young Event Horse" || $classname === "Five Year Old Young Event Horse") { $scorevar = rand(1,10); $score1 = $scorevar * $dressage; $score2 = $scorevar + $xcountry; $score3 = $scorevar * $jump; $final = $score1 + $score2 + $score3; echo "Horse # $horseid scored $score1, $score2, and $score3 for $final in class $classname <br/>"; } How can I get it to add the horseid, score1, score2, score3, final score, and classname into a database, sorted by final score lowest to highest with the appropriate placing (1st, 2nd, 3rd, ect.) with the scores? Quote Link to comment https://forums.phpfreaks.com/topic/242024-need-to-place-results/ Share on other sites More sharing options...
djlee Posted July 14, 2011 Share Posted July 14, 2011 would it not be easier to add them into the database and use an order by score when pulling them out ? Just knocked up some example code if you dont wanna go the database route <?php $horses = array(); $horses[] = array('name'=>'fred', 'score'=>34); $horses[] = array('name'=>'gary', 'score'=>12); $horses[] = array('name'=>'lee', 'score'=>45); $horses[] = array('name'=>'duke', 'score'=>10); $horses[] = array('name'=>'bill', 'score'=>13); $scores = array(); foreach ($horses as $key => $row) { $scores[$key] = $row['score']; } array_multisort($scores, SORT_DESC,$horses); print_r($horses); ?> whack it in a php script, run it and mess around with it Quote Link to comment https://forums.phpfreaks.com/topic/242024-need-to-place-results/#findComment-1242893 Share on other sites More sharing options...
AnAmericanGunner Posted July 15, 2011 Author Share Posted July 15, 2011 I will mess around with that, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/242024-need-to-place-results/#findComment-1243246 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.