Hi all,
I have the following script that will populate fields within a form from data extracted from the database.
Here is the code
NB $syn_name is the symbolic name of the fields I am populating.
The code works fine, except one thing. The list of options being displayed actually starts on the 3rd value. So each field I am populating is being populated with a list of value extracted from the database.
The list should being with the first value, but it actually starts on the 3rd value. The only field that actually works correctly is the last one in the array (infact, it doesn't matter which order the array is in, the last value to be displayed on the form always displays the first value correctly)... and I have no idea why..
Does anyone understand waht I'm trying to explain?
Does anyone have a clue what I'm doing wrong?
Any help/advice/further questions/explainations would be greatly welcommed.
Thanks,
Tony
I have the following script that will populate fields within a form from data extracted from the database.
Here is the code
Code:
global $db;
$groups = array();
$res = $db->query(new Query("SELECT groupid,groupname FROM groups ORDER BY groupname ASC"));
while (list($group_id, $group_name) = $res->fetchRow())
{
$groups[$group_id] = $group_name;
}
$sym_names = array("desk_name2","desk_name3","desk_name4","desk_name5","desk_name6","desk_name7","desk_name8");
$items = "";
foreach ($groups as $group_id => $group_name)
{
$items .= ($group_name.",#".$group_id."\n");
}
$items = trim($items);
$ret = NULL;
foreach ($params["form_fields"] as $field_symname => $field_info)
{
if (in_array($field_info["sym_name"], $sym_names, true))
{
$ret["form_fields"][$field_symname]["items"] = $items;
}
}
NB $syn_name is the symbolic name of the fields I am populating.
The code works fine, except one thing. The list of options being displayed actually starts on the 3rd value. So each field I am populating is being populated with a list of value extracted from the database.
The list should being with the first value, but it actually starts on the 3rd value. The only field that actually works correctly is the last one in the array (infact, it doesn't matter which order the array is in, the last value to be displayed on the form always displays the first value correctly)... and I have no idea why..
Does anyone understand waht I'm trying to explain?
Does anyone have a clue what I'm doing wrong?
Any help/advice/further questions/explainations would be greatly welcommed.
Thanks,
Tony