[eluser]eric cumbee[/eluser]
i am working on a facebook app and am trying to generate a dropdown select box with FBML. i have built my model function to get the state id and name from the database and drop them into an array. i call that function from the controller and pass that data to the view. when i try i echoing out the resulting array as a parameter of echo form_dropdown() it works fine. but when i try building option statements for the fbml select box or i try echoing out the data in a foreach(as seen in the view code posted below) all i get the first letter of each state name repeated twice (the output is at the bottom). i have been trying to figure out what i am doing wrong all afternoon. i am hoping a fresh set of eyes might help.
Model Function
Code:
function Get_all_states()
{
$states = array();
$this->db->select('id,name');
$query = $this->db->get('state');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$states[$row->id] = $row->name;
}
}
return $states;
}
controller function
Code:
function select_state()
{
$this->load->helper('form');
$this->load->model('geo');
$data['states'] = $this->geo->Get_all_states();
$this->load->view('/voters/selectstate',$data);
}
View Code
Code:
<?php
foreach($states as $rows)
{
echo $rows['id'];
echo $rows['name'];
echo '</br>';
}
?>
output
Code:
AA
AA
AA
AA
CC
CC
CC
DD
DD
FF
GG
HH
II
II
II
II
KK
KK
LL
MM
MM
MM
MM
MM
MM
MM
MM
NN
NN
NN
NN
NN
NN
NN
NN
OO
OO
OO
PP
RR
SS
SS
TT
TT
UU
VV
VV
WW
WW
WW
WW
AA
MM
GG
MM
NN
PP
PP
VV
AA
AA
AA