我正在使用这些代码
$query = "SELECT date FROM arrival order by date" ;
$result = mysqli_query($con,$query)or die ("Error". mysqli_error($con)) ;
echo "<select name='per1' id='per1'>";
while ($row = mysqli_fetch_array ($result)){?>
<option value=<?php echo $row['date'];?> selected='selected'><?php echo $row['date'];?></option>
</select>
<?php
}
?>
选择(选项列表)将数据显示为
2016-07-01 2016-07-02 2016-07-03 2016-07-04 2016-07-05 2016-07-06 and so on
它不像下拉选项列表。 如何使其像下拉列表一样?
我想从选项中选择一个日期。
答案 0 :(得分:0)
您要多次关闭// your code
while($row = mysql_fetch_array($result)) { ?>
<input type="hidden" name="id[]" id="id" value="<?php echo $row['id'] ?>">
<div class="form-group">
<div style="float:left">
<label> Receipt No:</label>
<input type="text" class="form-control" style="width: 60% !important; color:#999999;" name="receipt_no[]" value="<?php echo $row['receipt_no']; ?>"<?php if($_SESSION['user_level'] == 2){ echo ' readonly="readonly"'; } ?>>
</div>
<div>
<label> Date: (yyyy-mm-dd)</label>
<input class="form-control" style="width: 20% !important;" type="text" name="subDate[]" value="<?php echo $row['subDate']; ?>"<?php if($_SESSION['user_level'] == 2){ echo ' readonly="readonly"'; } ?>>
</div>
</div>
<div class="form-group">
<label> Received with thanks from:</label>
<input class="form-control" style="width: 40% !important" type="text" name="name[]" id="name" value="<?php echo $row['name'] ?>">
</div>
<div class="form-group">
<label> Address:</label>
<input class="form-control" style="width: 40% !important" type="text" name="address[]" id="address" value="<?php echo $row['address'] ?>">
</div>
中的select
。将while
移到外面。
</select>
您还应该引用属性值。完整的例子:
}?> </select>
答案 1 :(得分:0)
有点混乱清理了一下并尝试了这个
$query = "SELECT date FROM arrival order by date" ;
$result = mysqli_query($con,$query)or die ("Error". mysqli_error($con)) ;
$result_array = array();
while($row = mysql_fetch_assoc($result))
{
$result_array[] = $row['date'];
}
echo "<select name='per1' id='per1'>";
foreach($result_array as $name){
echo'<option value="'.$name.'">'.$name.'</option>';
}
echo'</select>';
我相信这会做你想要的。