Forums
This topic is locked
Select List (Multiple) - Highlight Values
Posted 26 Jul 2006 13:58:51
1
has voted
26 Jul 2006 13:58:51 Matt Bailey posted:
This is quite complicated so I hope I can explain it correctly.I have a select list with 'allow multiple' ticked. The values and labels are pulled out of a db table. Then 'select value equal to' is linked to another db table that indicates which items are already selected.
My problem is that only the first value that is specified in the second table is being highlighted as selected.
Here are my recordsets:
<pre id=code><font face=courier size=2 id=code>$colname_selectedproductcodesRS = "-1";
if (isset($_GET['productID'])) {
$colname_selectedproductcodesRS = (get_magic_quotes_gpc()) ? $_GET['productID'] : addslashes($_GET['productID']);
}
mysql_select_db($database_jcladminConn, $jcladminConn);
$query_selectedproductcodesRS = sprintf("SELECT jcl_prod_productcodes.productcodeid, jcl_prod_productcodes.productcode, jcl_prod_productcodes.`description` FROM jcl_prod_productcodes LEFT JOIN jcl_prod_productcodes_link USING (productcodeid) WHERE jcl_prod_productcodes_link.productid = %s", GetSQLValueString($colname_selectedproductcodesRS, "int");
$selectedproductcodesRS = mysql_query($query_selectedproductcodesRS, $jcladminConn) or die(mysql_error());
$row_selectedproductcodesRS = mysql_fetch_assoc($selectedproductcodesRS);
$totalRows_selectedproductcodesRS = mysql_num_rows($selectedproductcodesRS);
mysql_select_db($database_jcladminConn, $jcladminConn);
$query_productcodesRS = "SELECT * FROM jcl_prod_productcodes";
$productcodesRS = mysql_query($query_productcodesRS, $jcladminConn) or die(mysql_error());
$row_productcodesRS = mysql_fetch_assoc($productcodesRS);
$totalRows_productcodesRS = mysql_num_rows($productcodesRS);</font id=code></pre id=code>
And here is my select list code:
<pre id=code><font face=courier size=2 id=code><form action="" name="productcodes" id="productcodes">
<select name="productcodeid[]" multiple>
<?php
do {
?>
<option value="<?php echo $row_productcodesRS['productcodeid']?>"<?php if (!(strcmp($row_productcodesRS['productcodeid'], $row_selectedproductcodesRS['productcodeid']))) {echo "selected=\"selected\"";} ?>><?php echo $row_productcodesRS['productcode']?></option>
<?php
} while ($row_productcodesRS = mysql_fetch_assoc($productcodesRS));
$rows = mysql_num_rows($productcodesRS);
if($rows > 0) {
mysql_data_seek($productcodesRS, 0);
$row_productcodesRS = mysql_fetch_assoc($productcodesRS);
}
?>
</select>
<input name="Submit" type="submit" id="Submit" value="Submit">
</form></font id=code></pre id=code>
Can anyone help?
___________________________________
"Some people say if you play a windows cd backwards it plays satanic messages. That's nothing, because if you play it forwards it installs windows!"