Jump to content

Select option selected/unselected


son

Recommended Posts

I have a multiple select list, which I populate from db. Depending if there is an association in between a company and a region I want to select the relevant region.The relevant query is:

$sql = '(SELECT r.region_id, r.region_name, 1 AS selected FROM region AS r, association AS a WHERE a.company_id=%d)';$sql = 'UNION';$sql = '(SELECT r.region_id, r.region_name, 0 AS selected FROM region AS r, association AS a WHERE a.company_id != %d)';$sql .= ' ORDER BY region_name ASC, selected DESC';

I display it via:

echo "<option value=\"{$county['region_id']}\"";    if ($county['selected'])      echo ' selected="selected"';    echo ">{$county['region_name']}</option>";

It does not select anything. Where am I going wrong?Son

Link to comment
Share on other sites

I have a multiple select list, which I populate from db. Depending if there is an association in between a company and a region I want to select the relevant region.The relevant query is:
$sql = '(SELECT r.region_id, r.region_name, 1 AS selected FROM region AS r, association AS a WHERE a.company_id=%d)';$sql = 'UNION';$sql = '(SELECT r.region_id, r.region_name, 0 AS selected FROM region AS r, association AS a WHERE a.company_id != %d)';$sql .= ' ORDER BY region_name ASC, selected DESC';

I display it via:

echo "<option value=\"{$county['region_id']}\"";    if ($county['selected'])      echo ' selected="selected"';    echo ">{$county['region_name']}</option>";

It does not select anything. Where am I going wrong?Son

Have it working now;-) (went wrong in second SELECT clause...Son
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...