Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/242024-need-to-place-results/
Share on other sites

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

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.