Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ordering lists

Status
Not open for further replies.

ToeKnee2

Programmer
Jun 8, 2006
21
GB
Hi all,

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
 
maybe the values in the db you use are empty, this might be causing your problem..
 
Sorry,

I actually fixed this already.

I added a default value to the list being displayed...

Code:
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;
   [b]     $ret["form_fields"][$field_symname]["default_value"] = 0;[/b]
        }
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top