[eluser]doubleplusgood[/eluser]
Hi there,
I'm trying to do a region select drop down. But I'd like the regions group in the same select for England, Scotland and Wales.
Here's a sample of the database table as it stands at the moment with some regions and countries;
+----+---------------------+----------+
| id | name | country |
+----+---------------------+----------+
| 1 | East Midlands | england |
| 2 | East of England | england |
| 3 | North East Scotland | scotland |
| 4 | Highlands | scotland |
| 5 | Mid and West Wales | wales |
| 6 | North Wales | wales |
+----|---------------------+----------+
So far, I just have a select showing the England regions as follows;
Code:
<select name="region">
<option value="-">-</option>
<?php foreach($regions as $item) : ?>
<option value="<?php echo $item['id']?>" <?php if($this->input->get_post('region') == $item['id']) echo 'selected' ?>><?php echo $item['name']?></option>
<?php endforeach; ?>
</select>
And my Model;
Code:
public function getRegions(){
$this->db->order_by("name", "asc");
$query=$this->db->get('regions');
if($query->num_rows()>0){
// return result set as an associative array
return $query->result_array();
}
}
So basically, i'm wondering if anyone could point me in the right direction on how to group the regions in the select so that it would follow this sort of format?
Code:
<select name="regions">
<optgroup label="england">
<option value=""></option>
<option value=""></option>
<option value=""></option>
</optgroup>
<optgroup label="scotland">
<option value=""></option>
<option value=""></option>
<option value=""></option>
</optgroup>
<optgroup label="wales">
<option value=""></option>
<option value=""></option>
<option value=""></option>
</optgroup>
</select>
Thank you.