Hi Everyone...
I have been digging around the web for the last two days trying to fix this problem myself, but have come to the realization that I need some help.
I have a mysql query that selects all country names from my country db, (works as described)
I then have a select dropdown that is populated from the above query.
Here is the mysql select.
$result_country = $Db->query('select Country from countries order by Country Desc ');
Here is the select dropdown.
<select name="country" tabindex="2" class="span3" value='<?php echo $country; ?>' id="country" data-placement="right" rel="tooltip" title="Select your Country..">
<?php if($country!=''){?>
<option value="<?php echo $country;?>"><?php echo $country;?></option>
<?php }else{ ?>
<option value="">-- Select Country --</option>
<?php }?>
<?php
while($country_arr = mysql_fetch_array($result_country)){
$tag_selected = ( (isset($_POST['country']) and $_POST['country'] == $country_arr['Country'] )? 'selected="selected"' : '' );
?>
<option value="<?php echo $country_arr['Country']?>" <?php echo $tag_selected; ?>><?php echo $country_arr['Country']?></option>
<?php
}
?>
</select>
This works great & as expected, I get a full list of Country names populating the dropdown box.
The problem is, I am teaching myself PHP PDO / MySqli for safer coding.
On my new form I have this query to select all country name from my countries db.
$result_country = $Db->query('select Country from countries order by Country Desc');
This works as described, I know it works using a foreach loop like this.
<?php foreach($result_country as $row) : ?>
<h2><?php echo $row['Country']; ?></h2>
<?php endforeach; ?>
The problem I am having is adding this foreach to my select dropdown.
Any help with this would be greatly appreciated.
Thanks