我在此代码中遇到问题: `
<?php echo "Choose a date";
$reservation_date = $rm->retrieveReservation();
$data_date = array();
while($row_date = mysql_fetch_assoc($reservation_date)){
array_push($data_date, $row_date);
$dateOptions = ""
. "<select class='filter'>"
. "<option value='<?php echo $row['date'] ; ?>'><?php echo $row['date'] ; ?></option>"
. "</select>";
echo $dateOptions;
} ?>
?>
我想在下拉菜单中输出Sql行值。提前谢谢!
答案 0 :(得分:1)
您不必在此时回复<select>
,您应该这样做:
<?php echo "Choose a date";
$reservation_date = $rm->retrieveReservation();
$data_date = array();
$dateOptions = "<select class='filter'>";
while($row = mysql_fetch_assoc($reservation_date)){
array_push($data_date, $row_date);
$dateOptions = "<option value='". $row['date']."'>". $row['date'] ."</option>";
} ?>
$dateOptions = "</select>";
echo $dateOptions;
?>
答案 1 :(得分:0)
这应该有效:
echo "<select class='filter'>";
while($row = mysql_fetch_assoc($reservation_date)){
echo "<option value='".$row['date']."'>".$row['date']."</option>";
}
echo "</select>";
您需要在循环之外使用select
标记。你的PHP中也有一堆语法错误。
答案 2 :(得分:0)
<?php echo "Choose a date";
echo "<select class='filter'>";
$reservation_date = $rm->retrieveReservation();
$data_date = array();
while($row_date = mysql_fetch_assoc($reservation_date)){
array_push($data_date, $row_date);
$dateOptions = "<option value='{$row['date']}'>{$row['date']}</option>";
echo $dateOptions;
}
echo "</select>";
?>
这段代码可能适合你。