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:
x
<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
Advertisement
Answer
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
}
}
}
?>
update the code