-1
<tr>
<td>Subject:</td>
<td>
<select name="Subject">
<option value="<?php echo $Subject;?>"></option>
</select>
</td>
</tr>
<?php
$connection = mysqli_connect("localhost", "root", "", "phobiamming") or die (mysqli_error());
$sql = "SELECT * FROM section";
$result = mysqli_query($connection, $sql);
while ($row= mysqli_fetch_array($result)) {
echo $row['Subject'];
}
$connection->close();
?>
DBからコンボボックスにデータを表示できません。私のコードが正しいかどうかわかりません。データベースからデータを取得し、htmlのコンボボックスに表示する方法
<tr>
<td>Subject:</td>
<td><select name="Subject">
<option value="Subject"><?php $connection = mysqli_connect("localhost", "root", "", "phobiamming") or die (mysqli_error());
// SQL query
$strSQL = "SELECT * FROM sections";
// Execute the query (the recordset $rs contains the result)
$rs = mysqli_query($connection, $strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysqli_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo $row['Subject']. "<br>";
}
// Close the database connection
$connection->close(); ?></option>
</select></td>
</tr>
これは私の更新されたコードですが、私はすでにDBからのデータを表示することができますが、別の問題が表示されますDBの行である、それは改行を作成することはできません
あなたが持っているエラーを追加するために質問を編集できますか? –
@DatNguyen唯一の問題は、DBからコンボボックスにデータを表示できないことです –