-1
我想爲moduleID
取一列數,這樣我就可以在一個下拉列表中將模塊排列爲1,2,3而不是moduleID。我希望計數,以便我不能排列更多的模塊比可用。這是我到目前爲止有:但排名沒有出現:MySql和PhP - 創建一個數據庫列的排名下拉列表
`<`!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module Selector</title>
<style>
tr {background-color:lightblue;}
td {text-align:center;}
</style>
</head>
<body>
<?php
require_once "includes/connection.inc.php";
$conn = dbConnect();
//echo 'connected';
$sql = "SELECT * FROM module";
$nRows ="select moduleID, count(moduleID) from module";
$stmt = $conn->prepare($sql);
try {
$stmt->execute();
$results = $stmt->fetchAll();
if (!$results){ // check we have some results
echo "No modules Available at this Time try again later <br />";
}
else{ //generate table of modules
print "<table>\n";
echo "<th>ModuleID</th><th>Name</th><th>Description</th><th>Lecturer</th><th>Ranking</th>";
foreach ($results as $row){
echo "<tr>";
echo "<td>".$row["moduleID"]."</td>";
echo "<td>".$row["ModuleName"]."</td>";
echo "<td>".$row["ModuleDesc"]."</td>";
echo "<td>".$row["LecturerID"]."</td>";
echo "<td>".$row[ $nRows]."</td>";
}
print "</table>\n";
}
} catch (PDOException $e) {
echo "Query failed: " . $e->getMessage();
}
// close database connection
dbClose($conn);
?>
</body>
</html>
得到計數'我使用PDO「 - 真的嗎?看起來像我的老mysql擴展... – DaveRandom
你能提供表定義嗎? – LostMohican
爲了記錄,您沒有使用PDO。 PDO代碼看起來不像這樣。 – GordonM