multiple select: Selections not highlighted
| From: | Fahim Mohammad | Date: | Sat, 21 May 2011 15:11:54 +0000 |
| Subject: | multiple select: Selections not highlighted | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-47795@lists.php.net to get a copy of this message | ||
**
------------------------------
Hi
I implemented multiselect from the result of mysql query. When I print the
$val (in the end of the code below), it correctly shows all the option being
selected in _GET variable but the items are not selected(highlighted) in the
box. I am guessing the problem is with the declaration and usage of variable
'arrTypeTarget' but may be wrong.
Any suggestion?
Thanks
Fahim
<?php
$conn = mysql_connect('localhost', 'root', 'fahim');
$db = mysql_select_db('rugit',$conn);
if (!$db) die("Unable to connect to MySQL: " . mysql_error());
$arrTypeTarget = null; //declare vars
if(isset($_GET["arrTypeTarget"]) && is_string($_GET["arrTypeTarget"]))
{
$arrTypeTarget = $_GET["arrTypeTarget"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get" enctype="multipart/form-data">
<?php
$query = strtolower("show tables like \"human%\"");
print("query is $query");
$result = mysql_query($query, $conn);
$nRows = mysql_num_rows($result);
print"nRows is $nRows";
?>
<br></br>
Select the target array type: <br>
<select name="arrTypeTarget[]" size = "5" multiple="multiple" id =
"arrTypeTarget" onChange="autoSubmit();">
<?php
print("result is $result");
while($row = mysql_fetch_array($result))
{
echo ("<option value=\"$row[0]\" " . ($arrTypeTarget == $row["0"] ?
"
selected" : "") . ">$row[0]</option>");
}
echo"</select><br>";
$val = implode(", ", $_GET["arrTypeTarget"]);
print("arrTypeTarget is: $val");
?>
</form>
----
Fahim