HI everyone i have a problem this is the result
This is my codes.
$iqry2 = $mysqli->prepare("SELECT itemname,unitmeasure FROM table_item");
$iqry2->execute();
$iqry2->bind_result($itemname,$unitmeasure);
$iqry2->store_result();
<div class="form-group ">
<label for="itemname" class="control-label col-lg-2">Item Name</label>
<div class="col-lg-10">
<select name="iname" class="form-control">
<?php
while ($iqry2->fetch()){
echo "<option>$itemname</option>";
?>
</select>
</div>
</div>
<select name="unit" class="form-control">
<?php
echo "<option>$brandname</option>";
}
?>
</select>
</div>
</div>
You also have
</select>
</div>
</div>
<select name="unit" class="form-control">
Within your while loop, so instead of filling 2 select
boxes, you continuously close and open new drop-downs.
Change it to:
<?php
$items = array();
$brands = array();
// First create 2 arrays with all options
while ($iqry2->fetch()){
$items[] = $itemname;
$brands[] = $brandname;
}
$iqry2->close();
?>
<!--Now use those arrays to fill 2 seperate selectboxes-->
<select name="iname" class="form-control">
<?php foreach($items as $item):?>
<option><?=$item?></option>
<?php endforeach;?>
</select>
<select name="unit" class="form-control">
<?php foreach($brands as $brand):?>
<option><?=$brand?></option>
<?php endforeach;?>
</select>
Are you certain that your query is not returning empty?
You should do a vardump() of the data returned by your query. If it's NULL or FALSE, then you need to modify your query to check if it's empty or not. If not empty, then proceed.
What are you trying to do ? You have 1 or 2 selects ? You make a while, wich is supposed to push only <option>
, but in your while you write a <select>
tag wich is in another select...
<select name="iname" class="form-control">
<?php
while ($iqry2->fetch()){
echo "<option>$itemname</option>";
} // Add this bracket here to finish your while
?>
</select>
<select name="unit" class="form-control">
<?php
// You need another while here
while ( ???? ) {
echo "<option>$brandname</option>";
}
?>
</select>
I'm not sure what you wanna do but i think you must do 2 sql requests, one select itemname...
and then a second for select brandname
But reading your code i really don't know what's your expectation :(