I am trying to display the best player on a page and using this php code to get the result
<?php
//include database connection
include 'db_connect.php';
//query all records from the database
$query = "select cwins, close, name, id
from cseason ORDER BY cwins DESC LIMIT 1";
//execute the query
$result = $mysqli->query( $query );
//get number of rows returned
$num_results = $result->num_rows;
//this will link us to our add.php to create new record
if( $num_results > 0){
//loop to show each records
while( $row = $result->fetch_assoc() ){
//extract row
//this will make $row['firstname'] to
//just $firstname only
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>{$name}</td>";
echo '<td align="center">';
if (($cwins + $close) != 0) $rate = (($cwins / ($cwins + $close)) * 100);
else $rate = 0;
if ($rate > 70) {
echo "<span class='badge badge-success'>";
print round ($rate);
} elseif ($rate < 40) {
echo "<span class='badge badge-important'>";
print round ($rate);
}
else {
echo "<span class='badge badge-warning'>";
print round ($rate);
}
echo '</span>';
echo '</td>';
}
echo "</tr></table>";//end table
}else{
//if database table is empty
echo "No records found.";
}
//disconnect from database
$result->free();
$mysqli->close();
?>
Here is the data in cseason
[ id ] [ name ] [ cwins ] [ close ]
- - - - - - - - - - - - - - - - - - - - - - - - - - -- - -
[ 1 ] [ rick ] [ 11 ] [ 1 ]
[ 2 ] [ dave ] [ 6 ] [ 6 ]
[ 3 ] [ neil ] [ 7 ] [ 5 ]
[ 4 ] [ simon ] [ 3 ] [ 9 ]
It currently displays Neil which is wrong.
I ran the code directly in phpmyadmin and it comes up with the same answer.
Where have I gone or what have I over seen?
Ok i have gone into phpMYadmin to investigate there and found when i try to reorder the column 'cwins' the row neil still goes to the top...