gpt4 book ai didi

PHP 和 MySql 查询

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:27 27 4
gpt4 key购买 nike

您好,我创建了一个简单的脚本,可以从数据库中获取前 10 名最高分的结果。这是代码:

<html><head><title>MySQL Table Viewer</title></head><body>
<?php
$db_host = 'localhost';
$db_user = 'aa_quiz';
$db_pwd = 'mypassword';

$database = 'aa_quiz';
$table = 'aaresult';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

// sending query
$result = mysql_query("SELECT Candidate, Data5, Data3, OverAllScore, TotalPossibleScore, PercentageScore, PercentagePass, PassFail FROM {$table} WHERE QuizName='Test Quiz #505853118-1' ORDER BY OverAllScore DESC LIMIT 10");
if (!$result) {
die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";

echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>

但是我有一个问题。一个人可以多次参加测验,如果那个人在 OverAllScore 上两次得分更高,在前 10 名中显示两次,那么现在如果在这些前 10 名结果中,我该如何添加到我的脚本中Data3 列多次显示相同的值,然后只显示一次 OverAllScore 中数字最高的那条线。

最佳答案

尝试SELECT DISTINCT Candidate ...

关于PHP 和 MySql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9003367/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com