我正在尝试将我的数据库表格中的数据输入到下拉列表中,我遇到了一些困难。
<?php
session_start();
require_once("functions/User.cookies.php");
require("functions/MySQL_class.php");
$event = new MySQL_class();
$event->Create();
$event->Query("SELECT eid, `name`, date, `details`, vid, `mdetails`FROM event order by Date ");
for($i=0; $i<$event->rows; $i++){
$event->Fetch($i);
}
?>
<!DOCTYPE html PUBLIC>
<html>
<body>
<div id="Createevent">
<h1>create an event</h1>
<form action="functions/C_create.php" method="post">
<label>Event Name</label>
<input type="text" name="inputname" class="text requiredField subject" value="" /><br/><br/>
<label>Date</label>
<input type="date" name="inputdate" class="text requiredField subject" value="" /><br/><br/>
<label>Deatils</label>
<input type="text" name="inputdetails" class="text requiredField subject" value="" /><br/><br/>
<label>Venue</label>
<select name"select" class"textfeilds" >
<option id="0"> -- select your venue --</option>
<?php
require("functions/MySQL_class.php");
$event = new MySQL_class();
$event->Create();
$event->Query("SELECT * FROM venue ");
for($i=0; $i<$event->rows; $i++){
$event->Fetch($i);
?>
<option id="<?php echo $event->Create['vid']; ?> "><?php echo $event->Create['name'] ?></option>
<?php } ?>
</select>
<input name="submit" id="submit" value="Submit" class="button big red" type="submit"/>
</form>
</div>
答案 0 :(得分:0)
我知道您希望从数据库中获取数据提取的下拉列表,因此请更新您的代码,如:
<?php
// try this
$event->Query("SELECT * FROM venue ");
while($row = $event->Fetch()) {
echo '<option id="'.$row['vid'].'">'.$row['name'].'</option>';
}
?>