-
ARRARY list of countries from a database
At one point I was needing help with ARRAY’s, but couldn’t find any help on what I needed. I finally figured it out, so I thought I would post it in case anyone needed it.
The below code is how to create an ARRARY list of countries from a database and display it in a select dropdown box.
'Create Country ARRAY list
Recordset.Open "select count(id) as country_total from country",Connection
country_array_size = Recordset("country_total") - 1 ' Get Array Size, we minus 1 becuase array start at 0
Recordset.Close
Recordset.Open "select * from country",Connection
Redim country_array(country_array_size) 'Init Array
country_array_counter = 0 'Start Array At Zero
Do While NOT Recordset.Eof
country_array(country_array_counter) = Recordset("Country_Name")
country_array_counter = country_array_counter + 1 'Increment Array Counter
Recordset.MoveNext
Loop
Recordset.Close
'End Create Country ARRAY list
'Start Select Dropdown Box
Response.write "<select id=""adm_country"" onchange=""admin_update_project_country('"&db_id&"',this.value)"">"
For i = 0 to country_array_size
if country_array(i) = “Your Value” Then
Response.write "<option selected value="""&country_array(i)&""">"&country_array(i)&"</option>"
else
Response.write "<option value="""&country_array(i)&""">"&country_array(i)&"</option>"
end if
Next
Response.write "</select>"
'End Select Dropdown Box
Regards,
Tom M.
Software Consultant
www.advtoolware.com
www.idmcommunity.com
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks