Welcome Guest, Not a member yet? Register   Sign In
Using form_dropdown with IDs and names
#1

[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>
&lt;?php foreach($q_team_dropdown->result() as $row ){
      $team_dropdown[$row['team_id']] = $row['team_name'];
   }
?&gt;
   <td>Pick a team</td>
   <td>&lt;?php echo form_dropdown('form1', $team_dropdown) ?&gt;</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/


Messages In This Thread
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 11:39 AM
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 12:23 PM
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 12:41 PM
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 02:55 PM
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 03:08 PM
Using form_dropdown with IDs and names - by El Forum - 04-10-2014, 04:58 PM
Using form_dropdown with IDs and names - by El Forum - 04-13-2014, 11:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB