son Posted September 12, 2008 Share Posted September 12, 2008 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 More sharing options...
son Posted September 12, 2008 Author Share Posted September 12, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.