Select box
Permalink 1 user found helpful
Hi,
Im trying to create a selectbox that shows every item on the table but instead of showing all 10 values correctly, it shows "ARRAY" for each of the 10 items.
Code from the controller:
Code from the form:
Thanks for your help.
Im trying to create a selectbox that shows every item on the table but instead of showing all 10 values correctly, it shows "ARRAY" for each of the 10 items.
Code from the controller:
function getChurch() { $db = Loader::db(); $items = array(); $items=$db->GetArray("SELECT * FROM {$this->btChurch}"); return $items; }
Code from the form:
Thanks for your help.
That works, thank you.
However, I need to save the ID of the church selected in my database table, not the name. What is the best way to do that?
However, I need to save the ID of the church selected in my database table, not the name. What is the best way to do that?
Bump. I am at work and I can't find the answer by myself.
Current code from the form:
Current code from the controller:
It works as it shows the name of church in the list, but won't save as it doesn't know the ID.
Current code from the form:
Current code from the controller:
function getChurch() { $db = Loader::db(); $items = array(); $item=$db->GetArray("SELECT * FROM {$this->btChurch}"); foreach ($item as $row) { $items[] = $row['churchName']; } return $items; }
It works as it shows the name of church in the list, but won't save as it doesn't know the ID.
I am not sure how your script works, but to get the church ID from the array $items, you can
or in the foreach loop:
I suspect that you need the webpage to show a list of the churches, but the value returned from the selection is supposed to be the churchID?
// 0 is here the row number, 0 is first, the last is count($items)-1; $churchID = $items[0]['churchID'];
or in the foreach loop:
$churchID = $row['churchID'];
I suspect that you need the webpage to show a list of the churches, but the value returned from the selection is supposed to be the churchID?
Yes, exacly. Can you detail the code a little bit more?
paalgg, what you said is exacly what it needs to do. Could you help me more?
This is what I am trying to do...
And in the form...
This is what I am trying to do...
<?php function getChurch() { $db = Loader::db(); $item=$db->GetArray("SELECT * FROM {$this->btChurch}"); foreach ($item as $row) { $items[] = array($row['churchID'] => $row['churchName']); } return $items; }
And in the form...
Hi,
I know this is old post but here is a way to do it
.
GB
I know this is old post but here is a way to do it
$items[$row['churchID']] = $row['churchName']
GB
Which version of this ended up working? ( all the code )
Example output from GetArray:
array('0'=>array('id'=>1, 'name'=>'Lars'), '1'=>array('id'=>2, 'name'=>'Truls'))
I recommend to look at the output by writing the array to webbrowser:
Another example, if you need all church names in one array, you have to do something like this with your output from function GetArray:
God bless! ;)