I have two database tables. The link between the two is the Business.UnitID and Unit.Unit_ID.
Business:
Business_ID | Business Code | Business Description | UnitID | LogoID
Unit:
Unit_ID | Unit Code | Unit Description
At the moment on my page I have a drop-down menu that only lists the [Unit code] and [Unit description].
Basically I want to change drop-down list so the [Business code] is grouped by the [Unit code] from the Unit table.
I am able to display the [Unit code] from the recordset separately:
Does anyone know how I can piece the two together so I end up with for example:
Thanks.
Business:
Business_ID | Business Code | Business Description | UnitID | LogoID
Unit:
Unit_ID | Unit Code | Unit Description
At the moment on my page I have a drop-down menu that only lists the [Unit code] and [Unit description].
Code:
<select name="Unit" id="Unit">
<%
str_SQL = "SELECT * FROM [Unit] ORDER BY [Unit Code] ASC;"
Set obj_RS1 = obj_CN.Execute(str_sql, adBoolean)
' Build the menu
While Not obj_RS1.EOF
str_Unit = obj_RS1("Unit code")
str_UnitDescription = obj_RS1("Unit description")
str_Option = "<option value=""" & """#Selected#>" & str_UnitID & " - " & " - " & str_UnitDescription & "</option>"
Response.Write vbtab & str_Option & vbcrlf
obj_RS1.MoveNext
Wend
%>
</select>
Basically I want to change drop-down list so the [Business code] is grouped by the [Unit code] from the Unit table.
I am able to display the [Unit code] from the recordset separately:
Code:
<%
str_sql = "SELECT [Unit Code] FROM [Unit];"
Set obj_RS1 = obj_CN.Execute(str_sql, adBoolean)
do until obj_RS1.EOF
for each x in obj_RS1.fields
Response.Write(x.value & "<br />")
next
Response.Write("<br />")
obj_RS1.MoveNext
loop
%>
Does anyone know how I can piece the two together so I end up with for example:
Code:
<optgroup label="Unit code 1">
<option value="Business code 1"> Business code 1</option>
</optgroup>
Thanks.