DESC查询未显示正确的结果

时间:2014-01-28 14:51:24

标签: php mysql

我正在尝试在页面上显示最佳播放器并使用此PHP代码获取结果

<?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();

?>     

以下是cseason中的数据

[     id    ] [   name    ] [   cwins     ] [   close   ]
- - - - - - - - - - - - - - - - - - - - - - - - - - -- - -
[     1    ]  [   rick    ] [      11     ] [       1   ]
[     2    ]  [   dave    ] [      6      ] [       6   ]
[     3    ]  [   neil    ] [      7      ] [       5   ]
[     4    ]  [   simon   ] [      3      ] [       9   ]

目前显示Neil是错误的。

我直接在phpmyadmin中运行代码,它得到了相同的答案。

我去哪了或者我看到了什么?


好的,我已经进入phpMYadmin进行调查,发现当我尝试重新排序列'cwins'时,行neil仍然会出现在顶部......

0 个答案:

没有答案
相关问题