Fill drop down list box with contents of table

How do I fill the contents of a list box with the contents of a ldatabase table.  There is only two fields in this database.  ID and Type.  I want to fill it with type.
sonicimpulseAsked:
Who is Participating?
 
erikTsomikConnect With a Mentor System Architect, CF programmer Commented:
I tryed this one on my dataabse and it works well
<cfquery name="fil" datasource="#application.datasource#">
select * from pictures
</cfquery>
<select name="ltype">
<cfoutput query="fil">
<option value="#pic_name#">#pic_name#</option>
</cfoutput>
</select>
0
 
erikTsomikSystem Architect, CF programmer Commented:
try this. That should work


<cfquery name="fil" datasourse=#name#>
 
select id,type from tablename
 
</cfqury>
 
<select name="fillBox">
<cfoutput query="fil">
<option value="#id#">#type#</option>
</cfoutput>
 
 
</select>

Open in new window

0
 
sonicimpulseAuthor Commented:
Getting a error an I can't figure out why.  I'm using mySQL if that helps at all.

 Context validation error for tag cfqury.
The end tag </cfqury> encountered on line 12 at column 3 requires a matching start tag.

The CFML compiler was processing:

    * The body of a cfquery tag beginning on line 8, column 2.

 
The error occurred in C:\ColdFusion8\wwwroot\myMobi\login\member\coupon.cfm: line 12

10 : select id,type from coupontypes
11 :  
12 : </cfqury>
13 :  
14 : <select name="ltype">
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
danrosenthalCommented:
typo...should be </CFQUERY>
0
 
erikTsomikSystem Architect, CF programmer Commented:
sorry about the error . it should be </cfquery>. Sorry about that
0
 
sonicimpulseAuthor Commented:
Now I get this error.  I have no clue what this means.  Never seen it before

 Attribute validation error for tag CFQUERY.
The tag does not allow the attribute(s) DATASOURSE. The valid attribute(s) are BLOCKFACTOR,CACHEDAFTER,CACHEDWITHIN,CONNECTSTRING,DATASOURCE,DBNAME,DBPOOL,DBSERVER,DBTYPE,DEBUG,MAXROWS,NAME,PASSWORD,PROVIDER,PROVIDERDSN,RESULT,SQL,TIMEOUT,USERNAME.
 
The error occurred in C:\ColdFusion8\wwwroot\myMobi\login\member\coupon.cfm: line 55

53 :
54 : </script>
55 : <cfquery name="fil" datasourse=#security#>
56 : SELECT id,type from coupontypes
57 : </cfquery>
0
 
erikTsomikSystem Architect, CF programmer Commented:
you forgot quotes
<cfquery name="fil" datasourse="#security#">
0
 
sonicimpulseAuthor Commented:
I'm not getting an errors or data into the list box?  Any ideas why.  I double check the table to make sure it does have data and there is 7 rows of it.
0
 
erikTsomikSystem Architect, CF programmer Commented:
try to change to this
<select name="fillBox">
<cfoutput query="fil">
<option value="#fil.id#">#fil.type#</option>
</cfoutput>
 
 
</select>

or change cfoutput to cfloop
<cfoutput>
<select name="fillBox">
<cfloop query="fil">
<option value="#fil.id#">#fil.type#</option>
</cfloop>
</cfoutput>
 
</select>
0
 
erikTsomikSystem Architect, CF programmer Commented:
and also make sure that the datasource is correct
0
 
sonicimpulseAuthor Commented:
Its correct.  Not sure why its not working.  Even tried to take out the # signs for the datasource still did not work.
0
 
erikTsomikSystem Architect, CF programmer Commented:
can you post your script

0
 
sonicimpulseAuthor Commented:
<cfquery name="fil" datasourse="security">
SELECT id,type from coupontypes
</cfquery>
<select name="ltype">
<cfoutput query="fil">
<option value="#id#">#type#</option>
</cfoutput>
</select>

Name of the list box is ltype
0
 
erikTsomikSystem Architect, CF programmer Commented:
from what I can see you should be getting erors because it should be this DATASOURCE  not what you have <cfquery name="fil" datasourse="security">
0
 
sonicimpulseAuthor Commented:
<cfquery name="fil" datasourse="security">
SELECT id,type from coupontypes
</cfquery>
<select name="ltype">
<cfoutput query="fil">
<option value="#id#">#type#</option>
</cfoutput>
</select>

Name of the list box is ltype
0
 
sonicimpulseAuthor Commented:
<cfquery name="fil" datasourse="security">
SELECT id,type from coupontypes
</cfquery>
<select name="ltype">
<cfoutput query="fil">
<option value="#id#">#type#</option>
</cfoutput>
</select>

Name of the list box is ltype
0
 
erikTsomikSystem Architect, CF programmer Commented:
why are you double post the same thing
0
 
sonicimpulseAuthor Commented:
<cfquery name="fil" datasourse="security">
SELECT id,type from coupontypes
</cfquery>
<select name="ltype">
<cfoutput query="fil">
<option value="#id#">#type#</option>
</cfoutput>
</select>

Name of the list box is ltype
0
 
sonicimpulseAuthor Commented:
Not sure why its doing that.  Internet at work sucks
0
 
erikTsomikSystem Architect, CF programmer Commented:
so is it still does not work . But it must. can you also post you datasourse declaration
0
 
erikTsomikSystem Architect, CF programmer Commented:
name of the list box does not matter in this case
0
 
erikTsomikSystem Architect, CF programmer Commented:
please post application.cfm file so I can see how you declaring datasourse
0
 
sonicimpulseAuthor Commented:
I got it working correctly but the drop down box is on top of the page.  Does this need put in the application.cfm file?  If so I did not do that
0
 
sonicimpulseAuthor Commented:
ok I got it working correctly without puting it in the application.cfm file.  If its better practice to do that could you please let me know how?
0
 
erikTsomikSystem Architect, CF programmer Commented:
the best practice is to daclare the datasourse iin application.cfm so you would not have to type user name and password over and over again for example

application.cfm
<cfset application.datasource="MySQLDB">

--comment . where MySQLDB is datasourse name that you create in coldfusion administrator (this is the place where you connect to the DB and entering user name an password)

Then you can call it in your cf files
<cfquery name="nameOfTheQuery" datasource="#application.datasource#">
0
 
erikTsomikSystem Architect, CF programmer Commented:
Do you have an access to the ColdFusion administrator. If you do go to the datasourse (on the left hand site ) and select add. So I after you get everything setup please follow steps above
0
 
erikTsomikSystem Architect, CF programmer Commented:
I think I went through the whole process can I get points now. If you have any questions about CF please ask me . I can give a lot of feedbacks

Thanks
0
 
erikTsomikSystem Architect, CF programmer Commented:
Thanks a lot . Please let me know if you need any help
0
 
danrosenthalCommented:
BTW...I noticed your problem was another typo:
<cfquery name="fil" datasourse="security">

should be:
<cfquery name="fil" datasource="security">
0
 
erikTsomikSystem Architect, CF programmer Commented:
that is correct . I know that it is how you declare the datasource in your application.cfm. Thanks for catching though
0
All Courses

From novice to tech pro — start learning today.