在这段代码中,我想在表中显示数据,代码中没有错误,但即使查询有我想要的结果,我仍然有一个空表,这里是代码以供更多理解
<?php
$connectdb = mysql_connect('localhost','root','sara', true ) or die ("Not Connect");
if (!$connectdb)
{
die('Could not connect :'. mysql_errno());
}
$selestdb = mysql_select_db('iexa', $connectdb) or die ("not selected database");
if (isset($_POST['examID'])) {
$examID = $_POST['examID'];
}
echo $examID;
echo "<br />";
$query = mysql_query("SELECT Question , Choise_1 , Choise_2 , Choise_3 , Choise_4 , Correct_Answer
FROM question_bank WHERE E_No='examID' ORDER BY Question asc") or die ("mysql error");
echo "<table width='40%' border='1' cellpadding='5'>
<tr>
<td>Qusetion </td>
<td>Choise 1</td>
<td>Choise 2</td>
<td>Choise 3</td>
<td>Choise 4</td>
<td>The correct answer</td>
</tr>";
echo $query;
while ($row = mysql_fetch_assoc($query)){
echo '
<tr>
<td>'.$row['Question'].'</td>
<td>' .$row['Choise_1'].'</td>
<td>' .$row['Choise_2'].'</td>
<td>' .$row['Choise_3'].'</td>
<td>' .$row['Choise_4'].'</td>
<td>' .$row['Correct_Answer'].'</td>
</tr>';
};
echo "</table>";
mysql_close($connectdb);
?>
最佳答案
问题可能在 E_No='examID'
应该是:
E_No='" . mysql_real_escape_string($_POST['examID']) . "'
如果它是整数值,您始终可以将其类型转换为整数。 查询看起来像:
"SELECT Question , Choise_1 , Choise_2 , Choise_3 , Choise_4 , Correct_Answer FROM question_bank WHERE E_No='" . mysql_real_escape_string($_POST['examID']) . "' ORDER BY Question asc"
关于php - 表中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10355427/