更准确地说。我有一个表“data”,其中有很多列,其中 2 个是:“Name”和“Score”分别是文本和整数类型。现在,无需编辑实际表格本身,我只需按分数降序打印所有名称。我想 O(N^2) 也应该可以工作,因为几乎没有 1000 个条目。我正在使用 php/mysql。
最佳答案
查询:
SELECT name, score FROM data ORDER BY score DESC
PHP (mysqli)。假设 $db 是您的数据库连接:
$stmt = $db->prepare("SELECT name, score FROM data ORDER BY score DESC");
$stmt->execute;
$result = $stmt->get_result;
$stmt->close();
while($row = $result->fetch_assoc()){
echo $row['name'];
echo ": ";
echo $row ['score'];
echo "</br>";
}
关于php - 如何在php/mysql中根据列高效打印数据库排序中的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29349596/