無法顯示數據庫中的表格。每個節目都有一個表格,其中保存了一些分數。此外,還有一個節目表,其中保存了program id
和program name
。當我每年評選程序,我得到了以下錯誤:無法顯示數據庫中的表格
沒有找到數據
注意:未定義的變量:結果在C:\ XAMPP \ htdocs中\統計\ ac_directorPrograms.php上線61
警告:mysql_fetch_assoc()預計參數1是資源,在C空給出:\ XAMPP \ htdocs中\統計\ ac_directorPrograms.php上線61
出了差錯與result
從動作的代碼,我想用形式爲prog_name
和program
。
形式
<?php
include 'connect.php';
?>
<form name="myform" action="ac_directorPrograms.php" method="POST">
<b>Programs:<b/>
<select name="program">
<option value="Choose">Please select..</option>
<?php
$sql = mysql_query("SELECT prog_name FROM program");
while ($row = mysql_fetch_array($sql)) {
echo "<option value='" . $row['prog_name'] . "'>" . $row['prog_name'] ."</option>";
}
?>
</select><br/><br/>
<b>Year:<b/>
<select name="year">
<option value="Choose">Please select..</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option></select><br/><br/>
<br/>
<input type="submit" value="submit" name="Submit">
<input type="reset" name="reset" value="Clear">
</form>
</div>
行動碼
<?php
include 'connect.php';
$year = $_POST['year'];
$program = $_POST['program'];
$years = array(
2005,
2006,
2007
);
$programs = array(
'bsc computer science',
'bsc psychology',
'ba finance',
'ba marketing',
'ba management'
);
if (in_array($program, $programs) && in_array($year, $years)) {
$sql = "SELECT a1,a2,a3,l1,l2,l3,l4,l5,l6,l7,lavg,r1,r2,u1,u2,u3 FROM $program WHERE year=$year";
$result = mysql_query($sql);
}
else {
echo "No data found";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../statistics/style.css">
</head>
<body>
<div id="container">
<table id="table" width="900" border="1" cellspacing="1">
<tbody>
<tr>
<td>A1 </td>
<td>A2 </td>
<td>A3 </td>
<td>L1 </td>
<td>L2 </td>
<td>L3 </td>
<td>L4 </td>
<td>L5 </td>
<td>L6 </td>
<td>L7 </td>
<td>LAVG </td>
<td>R1 </td>
<td>R2 </td>
<td>U1 </td>
<td>U2 </td>
<td>U3 </td>
</tr>
</tbody>
<?php
while($program=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$program['a1']."</td>";
echo "<td>".$program['a2']."</td>";
echo "<td>".$pprogram['a3']."</td>";
echo "<td>".$pprogram['l1']."</td>";
echo "<td>".$program['l2']."</td>";
echo "<td>".$program['l3']."</td>";
echo "<td>".$program['l4']."</td>";
echo "<td>".$program['l5']."</td>";
echo "<td>".$program['l6']."</td>";
echo "<td>".$program['l7']."</td>";
echo "<td>".$program['lavg']."</td>";
echo "<td>".$program['r1']."</td>";
echo "<td>".$program['r2']."</td>";
echo "<td>".$program['u1']."</td>";
echo "<td>".$program['u2']."</td>";
echo "<td>".$program['u3']."</td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>
嘗試將這段代碼
$result = mysql_query($sql);
呼應SQL可能是你能進去,如果條件就是爲什麼結果沒有定義,你所得到的警告。開始使用mysqli或pdo。 –