I am using codeigniter for my project and I am passing array values on view.
Let me elaborate by giving a proper look to the view, controller and model structure.
Model:
public function getTournament() {
$this->db->select('tourn_id,tourn_name,tourn_teams');
$this->db->from('tournaments');
$query = $this->db->get();
return $query->result_array();
}
Controller
public function index() {
$result['tournament']=$this->matches_model->getTournament();
$this->template->set_layout('admin')->enable_parser(FALSE)->title('Add Matches - Cricnepal Live Update')->build('admin/add/matches_view', $result);
}
View:
<select name="tournament_match" class="form-control" id="tournament_match">
<option value=''>--- Select Tournament ---</option>
<?php
foreach ($tournament as $row):
$match_TournamentName=$row['tourn_name'];
$match_TournamentID=$row['tourn_id'];
$teamlist=$row['tourn_teams'];
echo '<option value='.$match_TournamentID.'>'.$match_TournamentName.'</option>';
endforeach;
?>
</select>
Problem:
<select name="tournament_match" class="form-control" id="tournament_match">
<option value="">--- Select Tournament ---</option>
<option value="1">Cricnepal Cricket Tournament</option>
<option value="2">Nepal Cricket Tournament</option>
</select>
I want to display a new select option field below it which shows the data of respected selected option value.
For example, if I select "Cricnepal Cricket Tournament" then I need to get all the associated data related to it from the database instantly using jQuery or other method so it can be added as a new option element.