在html select选项中显示来自sql的值不显示值 [英] displaying values from sql in html select option not displaying values
本文介绍了在html select选项中显示来自sql的值不显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用php和sql创建了一个html表单.该表单包含一个称为空格的字段,该字段是一个选择下拉列表.这些值来自我在php中声明的数组.如果数组中的值已经存在于数据库中,则不应显示.所以我完成了以下代码:
i have created a html form using php and sql. The form contains a field called spaces which is a select dropdown. The values are coming from an array which i declared in php. If the values in array are already present in database it should not display. So i have done the following code:
<select class="form-control" id="space" name="space">
<option value="--Select--">--Select--</option>
<?php
$select=mysqli_query($con,"select * from clients where Spaces IS NOT NULL");
while($menu1=mysqli_fetch_array($select))
{
$filled =$menu1['name'];
$valuez = array("C101","C102","C103","C104");
if ($filled != $valuez) {
?>
<option value="<?php echo $valuez;?>">
<?php echo $valuez;?>
</option>
<?php
}}
?>
</select>
但这不会显示任何值.谁能告诉我代码中有什么问题吗?谢谢你提前
but this is not making any values display. Can anyone please tell me what is wrong in my code. thanks n advance
推荐答案
您正在将字符串与数组进行比较.您应该像这样使用in_array
you are comparing a string with the array. you should use in_array like this
<select class="form-control" id="space" name="space">
<option value="--Select--">--Select--</option>
<?php
$select=mysqli_query($con,"select * from clients where Space IS NOT NULL");
while($menu1=mysqli_fetch_array($select))
{
$filled =$menu1['Space'];
$valuez = array("C101","C102","C103","C104");
foreach($valuez as $value){
if($value != $filled){
?>
<option value="<?php echo $value;?>">
<?php echo $value;?>
</option>
<?php
}
}
}
?>
更新代码
这篇关于在html select选项中显示来自sql的值不显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文