I have a problem to show my database values into a select box.
Here is my code
<select name="bugsolver">
<?php
if(count($yourBugs) > 0)
{
foreach( $emails as $key=> $singleEmail)
{ ?>
<option value="<?=$singleEmail['email']?>" selected='selected'> <?php echo $singleEmail['email']?></option>";
<?php }
} ?>
</select>
Your code should look like this:
<select name="bugsolver">
<?php
if(count($yourBugs) > 0):
foreach( $emails as $key=> $singleEmail ):
?>
<option value="<?php echo $singleEmail['email']; ?>">
<?php echo $singleEmail['email']; ?>
</option>
<?php
endforeach;
endif;
?>
</select>
When your code is easy to read (at least for you) it's easier to find bugs. If above code still doesn't work, do var_dump($yourBugs)
and var_dump($emails)
to check if these values are properly set. You can have disabled short tags (<?=
) or variables are just empty.
Your code seems be OK. Try to test for $emails instead $yourBugs to get more info:
<?php if (count($emails)) : // test if $emails have values ?>
<select name="bugsolver">
foreach( $emails as $key=> $singleEmail) { /* ... */ }
</select>
<?php else : ?>
There are no emails to select ($emails is empty)
<?php endif; ?>