Link to home
Start Free TrialLog in
Avatar of Michael Ambech
Michael Ambech

asked on

Populating dropdown menu using classic asp and mySQL

Hi all,

Being fairly new to coding in general. I have a page with dropdown menus available. I would like one of these to be customer  controlled and updateable. I know how to insert and update values in a mySQL database. However populating a dropdown menu using data from that database is an issue. I have 3 records in my database (Table name: Lokation - Column name: Lokation_navn). The below code clearly appears to be displaying these 3 records (it is 3 records long when I view it on the web page). However there is no text visible???? Any help and/or direction much appreciated!

Here is my code - strConnect represents the database credentials and comes from an include file at the top of the page:

<%
Dim objconn,objRS,strSQL

Set objconn = Server.CreateObject("ADODB.Connection")
objconn.Open strConnect

Set objRs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT distinct(Lokation_navn) FROM Lokation ORDER BY Lokation_navn Desc"
objRS.Open strSQL, objconn
Response.Write "<select name=lokation><option value='''' selected>Vælg lokation</option>"
Do While Not objRS.EOF 
Response.Write "<option value=''" & objrs("Lokation_navn") &"''>"& objRs("Lokation_navn") &"</option>"
objRS.MoveNext
Loop
Response.Write "</select>"
objRs.Close
objconn.Close

%>

Open in new window

SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Ambech
Michael Ambech

ASKER

HI both, thanks for your responses. I tried both, but none of them solved the problem though. I added two more records to the database - just to be sure. As you can see in the attached file, the dropdown list is still empty - but now it contains 5 records insted of three (excluding the selected one) - so the data is there?
User generated image
My database contains two columns as mentioned. Column setup posted here.

Id - MediumInt(11) - AUTOINCREMENT - This column is defined as an index (BTREE)
Lokation_navn - Text - utf8_danish_ci

Hope any of the info provided gave you something to Work with.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Accept yourself as answer, and award the points to one of the above or both experts for their assisted code.

I myself, like sammySeltzer's code, as it is clean, and helps you to troubleshoot much better than using the response.write all over your code.
(Do not accept this as assisted answer)
Good Luck with your ASP Classic Work.
Carrzkiss
I've requested that this question be closed as follows:

Accepted answer: 0 points for hjalteambech's comment #a41207745
Assisted answer: 50 points for The_Big_Daddy's comment #a41205985
Assisted answer: 50 points for sammySeltzer's comment #a41206966
Assisted answer: 400 points for carrzkiss's comment #a41240664

for the following reason:

Changing database column datatype to VARCHAR solved the problem. Thanks for all your input!
what??????
I've requested that this question be closed as follows:

Accepted answer: 0 points for hjalteambech's comment #a41207745
Assisted answer: 100 points for The_Big_Daddy's comment #a41205985
Assisted answer: 200 points for sammySeltzer's comment #a41206966

for the following reason:

It solved the underlying problem
Okay... Maybe I'm just too stupid for this website... The usability regarding awarding points to me at least is rather confusing...
I give up... Tried givng sammy 300 and monty 200. Didn't happen... Sorry guys!
Of course you can award yourself the points.
And if I actually read Mr. Wolfes comments and followed his links I would have been fine to begin with. Sorry guys... I'm off to stand upside down in a bucket of piranha fish....
A said before ... It solved the underlying problem. Is it okay to award myself points? I have no problem with distributing it between Sammy and Big Monty. Sorry about the confusion. To me at least it is rather annoying being asked to grade (taken to the bottom of the page) when you are reviewing answers for grading.