-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