first i'll try to explain my problem. I'm very new to codeigniter and i'm trying to make a drop down menu in codeigniter fetching results from database. I already made some experiences but doesn't work as it should.
first my model:
public function get_continents() {
$this->db->select('*');
$this->db->from('continents');
$this->db->order_by("continent_name", "asc");
$query = $this->db->get();
if($query->num_rows() > 0) {
return $query->result();
}
else {
return FALSE;
}
}
public function get_contries() {
$this->db->select('*');
$this->db->from('countries');
$this->db->join('continents', 'country_continent_id = continent_id', 'left');
$this->db->where('continent_id', $id);
$this->db->order_by('country_name', 'asc');
$query = $this->db->get();
if($query->num_rows() > 0) {
return $query->result();
}
else {
return FALSE;
}
}
now the controller:
public function index() {
$dados['title'] = 'Places to Visit';
$dados['page'] = 'home';
// lista dos continentes
$this->load->model('option_model');
$dados['continent'] = $this->option_model->get_continents();
// lista os paises
$dados['country'] = $this->option_model->get_contries();
// chamar a vista -> view
$this->load->view('home', $dados);
}
and the view:
<nav>
<ul>
<li><a href="" id="home">Homepage</a></li>
<?php foreach ($continent as $row) {; ?>
<li>
<a href="" id="<?php echo $row->continent_id; ?>"><?php echo $row->continent_name; ?></a>
<ul>
<?php foreach($country as $row2) {; ?>
<li><a href="" id="<?php echo $row2->country_id; ?>"><?php echo $row2->country_name; ?></a></li>
<?php }; ?>
</ul>
</li>
<?php } ?>
<li><a href="" id="pt">Portugal</a></li>
</ul>
</nav>
What i want to make is a menu of continents and each continent has a drop down with the countries like this:
> continent 1
- country 1
- country 2
- ...
> continent 2
- country 1
- country 2
- ...
> ...
how can i do this? Thanks in advance!