Ok I did get some code that shows a percentage. It shows it after the score out of 20 though. So it goes like " you scored 4/20 your percentage is 40" I am definatly moving in the right direction.
What I am looking for now is for the mark out of 20 to not be shown at all and only the percentage is shown. Also the score out of 20 goes to a leaderboard what I want is the percentage to go to the leaderboard instead.
I know I am a pain in the ass but Any help and I would be exstatic.
I will provide the code here.
This is the code in the test part that I belive will send it to the leaderboard and the one that shows the results.
<?php } else {
$file = "leaders.xml";
$xml = simplexml_load_file($file);
$user = $xml->addChild('user');
$uname = $user->addChild('name',$_SESSION['user']);
$uscore = $user->addChild('score',$_SESSION['score']);
$xml->asXML("leaders.xml");
echo "<h2 id=\"score\">{$_SESSION['user']}, your final score is:</h2>\n
<h3>{$_SESSION['score']}/20</h3><h4>Verdict:</h4>";
//changed code
$percent=$_SESSION['score']/20*100; //work out a percentage, divide the score by total an *100
echo "<p>Your Percentage: ".$percent."</p>";
if($_SESSION['score'] <= 5) echo "<p id=\"verdict\"><span>S</span>everely <span>H</span>indered <span>I</span>n the <span>T</span>est!</p>\n";
if(($_SESSION['score'] > 5) && ($_SESSION['score'] <= 10)) echo "<p id=\"verdict\"><span>C</span>ould <span>R</span>ead <span>A</span>nd <span>P</span>ractice more.</p>\n";
if(($_SESSION['score'] > 10) && ($_SESSION['score'] <= 15)) echo "<p id=\"verdict\"><span>A</span>cronyms a<span>R</span>e <span>S</span>o <span>E</span>asy!</p>\n";
if($_SESSION['score'] > 15) echo "<p id=\"verdict\"><span>S</span>uper <span>A</span>cronym <span>S</span>pecialist</p>";
echo "<p id=\"compare\"><a href=\"results.php\">See how you compare! <img src=\"images/arrow.png\" /></a></p>";
}
?>
This is the code in the XML file that is storing the the leader information
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<name>Bobby</name>
<score>10</score>
</user>
<user>
<name>Billy</name>
<score>1</score>
</user>
</users>
and this is the show leaders code from the functions.
function showLeaders($file,$limit,$group = null) {
$leaders = array();
// Load the xml file and place all users and associated
// scores into the 'leaders' array.
$xml = simplexml_load_file($file);
foreach($xml->user as $user) {
$name = (string)$user->name;
$score = (string)$user->score;
$leaders[$name] = $score;
}
// Sort the leaders array numerically, highest scorers first.
arsort($leaders,SORT_NUMERIC);
// Initialise our $counter variable to '1'.
$counter = 1;
// Start a html ordered list to hold the leaders.
$output = "<ul class=\"leaders\">\n";
// Loop through the 'leaders' array and wrap each username and score
// in <li> tags. If the user is the current $_SESSION['user'], wrap
// the name/score in <strong> tags too.
foreach ($leaders as $key => $value) {
// Check that $counter is less than $limit.
if ($counter <= $limit) {
if ($key == $_SESSION['user']) {
$output .= "<li><strong>$key:</strong> $value/20</li>\n";
} else {
$output .= "<li>$key: $value/20</li>\n";
}
// Check to see if $group parameter has been passed.
// If it has, create separate lists according to the $group variable.
if ($group) {
// Use the modulus operator(%) to create new sub-list.
if($counter % $group == 0) {
$output .= "</ul>\n<ul class=\"leaders\">\n";
}
}
}
// Increment the $counter.
$counter++;
}
// End the ordered list.
$output .= "</ul>\n";
// Print out the ordered list.
echo $output;
}
You have all been really helpful so far and this could be me if I get this going. Any and all help would be INSANELY grateful it really would. Thank you!