当选择值为null时,如何显示我想显示输入字段以输入客户自己的选择。我是php的新手,所以任何人都可以建议我怎么做?这是我的参考代码。
<select class="form-control" name="outlet">
<option>Select Outlet</option>
<?php
$values = explode(",",$camp_outlet);
foreach(explode(",",$camp_outlet) as $value){
?>
<option value="<?php echo "$value";?>">
<?php echo "$value";?>
</option>
<?php
}
?>
答案 0 :(得分:1)
<?php
$theData = explode(",",$camp_outlet);
if (count($theData) > 0 ){
echo "<select class=\"form-control\" name=\"outlet\">";
echo "<option>Select Outlet</option>";
foreach($theData as $value){ // loop through the data and add the options to the select input
echo "<option value=\"$value\">$value</option>";
}
echo "</select>";
} else {
echo "<input type=\"text\" class=\"form-control\" name=\"outlet\">";
}
?>