[eluser]Bisquite[/eluser]
Hi,
I know this question has been asked many times but I just can't implement the recommendations in my own solution. I have a form that has a dropdown box showing all the teams in the database, when the form is submitted the ID of that team is recorded in the database (the name is purely for displaying in the dropdown list).
So far I have:-
Model
Code:
public function get_team_dropdown() {
$query = "
select team_id, team_name
from teams
where club_id = 1
union
select team_id, team_name
from
(
select team_id, team_name
from teams
where club_id <> 1
order by team_name
) as s";
return $this->db->query($query);
}
View
Code:
<tr>
<?php foreach($q_team_dropdown->result() as $row ){
$team_dropdown[$row['team_id']] = $row['team_name'];
}
?>
<td>Pick a team</td>
<td><?php echo form_dropdown('form1', $team_dropdown) ?></td>
</tr>
Controller
Code:
$data['q_team_dropdown'] = $this->Matches_model->get_team_dropdown();
$this->load->view ('matches/new_match', $data);
This all worked fine when I just had the list of names, but now I've introduced the ID as a value and I get the error
Cannot use object of type stdClass as array
Any help is much appreciated.
Thanks,
b/