|
-
Jan 16th, 2013, 05:28 PM
#1
Thread Starter
Lively Member
[RESOLVED] Multiple Select List Box
I have a function that works correctly, by dynamically assigning a dataset to a drop down box and selecting a specific value based on the specific query row.
However now I need to do a similar thing for a multi select list box and I can't quite get my head round it.
Here is my code:
function drop_down($array_name,$field_id, $query_field_id, $field_name,$server_name,$user_name,$password,$database_name,$query_string,$row,$multiple) {
//-------------------------------------------------------------------------------------------------------------------------
$stat_array=get_dataset($server_name,$user_name,$password,$database_name,$query_string);
//echo "<select name=".$array_name." width='100%'>";
if(empty($multiple)) {
echo "<select name=".$array_name." width='100%'>";
if ($row[$field_id] == $thiscat[$query_field_id]) {}{echo "<option>None Selected</option>";}
}
else {echo "<select multiple size =".$multiple." name=".$array_name." width='100%'>";
}
foreach ($stat_array as $thiscat)
{
echo '<option value="' . $thiscat[$query_field_id] . '"';
if ($row[$field_id] == $thiscat[$query_field_id]) {echo ' selected';}
echo '>' . $thiscat[$field_name] . '</option>';
}
echo "</select>";
$db1->close;
}
//-------------------------------------------------------------------------------------------------------------------------
It renders the list box correctly, but I feel I need an additional loop possibly around this line:
if ($row[$field_id] == $thiscat[$query_field_id]) {echo ' selected';}
Will that then loop through all the selected values or do I need a different approach?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|