I find the percentages of correct answers with the following code: $per = ($row['correct'] / ($row['correct'] + $row['incorrect']))*'100'; When I echo $per, I naturally get a list. What I actually want is to echo only the highest value out of that list. How can I do that? Is it possible to make $per an array variable?
could you post the full code? / the code of that bit? $highest =0; while ($row = mysql_fetch_array($query)) { $per = ($row['correct'] / ($row['correct'] + $row['incorrect']))*'100'; if ($per>$highest) { $highest = $per; } } echo $highest; PHP:
Here it is: while($row = mysql_fetch_array( $result )) { if($row['incorrect'] > '0') { //to avoid dividing by zero $per = ($row['correct'] / ($row['correct'] + $row['incorrect']))*'100'; echo $per, "<br>"; } } PHP:
$highest =0; while($row = mysql_fetch_array( $result )) { if($row['incorrect'] > '0') { //to avoid dividing by zero $per = ($row['correct'] / ($row['correct'] + $row['incorrect']))*'100'; if ($per>$highest) { $highest = $per; } //echo $per, "<br>"; } } echo $highest; PHP: