coldfusion query list problem

I have the following, and the cfoutput did not output the value.  

;;;;;;;
<cfquery name="ClassOption" datasource="text_db">
SELECT  CLASS_ID,
      NAME
FROM TEXT_TB
</cfquery>

;;;;;;;;;;


<td colspan="3">Student Num:
            <input size="9" id="std_num" NAME="std_num" type="text">
            &nbsp;&nbsp;&nbsp;Start Date:
            <input size="8" id="std_date" NAME="std_date" type="text" value="#url.stddate#">

             <cfif isdefined("ClassOption.recordcount") and ClassOption.recordcount gt 0>
                 &nbsp;&nbsp;&nbsp;Class Option:
                <select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                    <cfloop index="i" from="1" to="#ClassOption.recordcount#">
                  <cfoutput><option value="#ClassOption.NAME#" ></cfoutput>
                    </cfloop>
                </select>
            </cfif>
</td>
jfreeman2010Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

srikanthmadishettiCommented:
First  dump your query classoption and see what all data it has .

You don't need is defined for record count if the query is there recordcount will be there for sure

change your code like this

<cfdump var="#ClassOption#">
<td colspan="3">Student Num:
            <input size="9" id="std_num" NAME="std_num" type="text">
            &nbsp;&nbsp;&nbsp;Start Date:
            <input size="8" id="std_date" NAME="std_date" type="text" value="#url.stddate#">

             <cfif  ClassOption.recordcount gt 0>
                 &nbsp;&nbsp;&nbsp;Class Option:
                <select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                    <cfloop index="i" from="1" to="#ClassOption.recordcount#">
                    <cfoutput query="ClassOption">
                          <option value="#ClassOption.NAME#" > </option>
                            </cfoutput>
               
                </select>
            </cfif>
</td>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_agx_Commented:

<select style="width: 420" id="copt" name="copt">
   <option value="-1" selected>Choose a Class option </option>
   <cfoutput query="ClassOption">
       <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME#</option>
    </cfoutput>
</select>
srikanthmadishettiCommented:
I see that in your code you didn't closed you <option> tag and also what should come in between option tags .

Please check view source and see how you html is coming .

I guess you need value column class_id and display one name

Change it to like this

<td colspan="3">Student Num:
            <input size="9" id="std_num" NAME="std_num" type="text">
            &nbsp;&nbsp;&nbsp;Start Date:
            <input size="8" id="std_date" NAME="std_date" type="text" value="#url.stddate#">

             <cfif  ClassOption.recordcount gt 0>
                 &nbsp;&nbsp;&nbsp;Class Option:
                <select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                    <cfloop index="i" from="1" to="#ClassOption.recordcount#">
                    <cfoutput query="ClassOption">
                          <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>
            </cfif>
</td>

   
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

_agx_Commented:
> I have the following, and the cfoutput did not output the value.  

It does.  But you forgot to generate the "text" for the list option.  Also, you probably meant to use the ID for the list value.  See my example above http:#a36945171

       <option value="(list value)">(list text)</option>
srikanthmadishettiCommented:
@agx

Again an mid air  collision between our comments  :)
_agx_Commented:
Yep :)  But don't forgot you don't need the extra cfloop now that we've switched to cfoutput.  It's just

<select style="width: 420" id="copt" name="copt">
   <option value="-1" selected>Choose a Class option </option>
   <cfoutput query="ClassOption">
       <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME#</option>
    </cfoutput>
</select>
srikanthmadishettiCommented:
oops yes i forgot to remove that

<td colspan="3">Student Num:
            <input size="9" id="std_num" NAME="std_num" type="text">
            &nbsp;&nbsp;&nbsp;Start Date:
            <input size="8" id="std_date" NAME="std_date" type="text" value="#url.stddate#">

             <cfif  ClassOption.recordcount gt 0>
                 &nbsp;&nbsp;&nbsp;Class Option:
                <select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                   
                    <cfoutput query="ClassOption">
                          <option value="#CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>
            </cfif>
</td>
_agx_Commented:
lol. We now have my example repeated 3 times.  Sorry jfreeman2010, we really don't think you're blind ;-)

http:#a36945171
http:#a36945226 
http:#a36945273
jfreeman2010Author Commented:
Thank you for all the help:

this did not work:

<select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                   
                    <cfoutput query="ClassOption">
                          <option value="#CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>

But this works:

<select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                    <cfloop index="i" from="1" to="#ClassOption.recordcount#">
                    <cfoutput>
                          <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>
jfreeman2010Author Commented:
Thank you for helping!!!
_agx_Commented:
> But this works:

No, actually it wouldn't. It would output the same class_id multiple times.

> this did not work:

How so? No reason it wouldn't work, unless maybe there's more going on than we can see? See working example below:

<cfset ClassOption = queryNew("")>

<cfset queryAddColumn(ClassOption, "Class_ID", listToArray("1,2,3,4"))>
<cfset queryAddColumn(ClassOption, "NAME", listToArray("A,B,C,D"))>

<form>
<select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                   
                    <cfoutput query="ClassOption">
                          <option value="#CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>
</form>
srikanthmadishettiCommented:
@jfreeman2010

This is wrong

<select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                    <cfloop index="i" from="1" to="#ClassOption.recordcount#">
                    <cfoutput>
                          <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>
because you are not running a query loop here instead loop from 1 to query record count times

so wen u display #ClassOption.CLASS_ID# like this it will display wrongly

this should work

<select style="width: 420" id="copt" name="copt">
                <option value="-1" selected>Choose a Class option  
                   
                    <cfoutput query="ClassOption">
                          <option value="#ClassOption.CLASS_ID#" >#ClassOption.NAME# </option>
                            </cfoutput>
               
                </select>

if it is not working can u copy the view source and paste here please if possible
_agx_Commented:
Based on the information provided, recommend #3 - accept http:#a36945171 . It properly populates the <select> list options from the provided query.  These corrections are used in subsequent comments.

The accepted answer http:#a36945165 does not produce the correct results. It's virtually identical to the original code and produces the same empty list options mentioned in the original question. Items are also duplicated many times over.

> But this works:
While http:#a36945378 incorporates some corrections from http:#a36945171, the final code would incorrectly repeat one value, over and over.

       <option value="1">First Item</option>
       <option value="1">First Item</option>   <== duplicated
       <option value="1">First Item</option>   <== duplicated
       ....

srikanthmadishettiCommented:
@agx

>>>  "The accepted answer http:#a36945165 does not produce the correct results. It's virtually identical to the original code and produces the same empty list options mentioned in the original question. Items are also duplicated many times over. "

comment #36945165  - it's not virtually identical to the original code  ,
I have used query loop
only that i forgot to remove

this statement "<cfloop index="i" from="1" to="#ClassOption.recordcount#"> "
before cfoutput

presently this will throw error so need to remove this statement
<cfloop index="i" from="1" to="#ClassOption.recordcount#">

I posted the comment removing this statement - comment # 36945273
_agx_Commented:
@sri - The correct solution should be marked for the archives.  Answer http:#a36945165 is not correct.  It produces the same empty list options that prompted the original question.

    original: <option value="#ClassOption.NAME#" ></cfoutput>  <== fails to produce option text
    new: <option value="#ClassOption.NAME#" > </option>    <== fails to produce option text





srikanthmadishettiCommented:
That is what i am saying too

Comment #36945165 is not correct it will throw error first of all
the correct one is

Comment # 36945273
_agx_Commented:
That just reiterates my correct answer which was given much earlier http:#a36945171 . The 2nd comment in fact.
srikanthmadishettiCommented:
@agx ,

So you wanted to your comment to be selected as Accepted answer.

I have No problem -

 I was just discussing to clarify on my comments .
_agx_Commented:
I understand.  I just want to make sure the correct answer is marked for anyone searching the archives.  Anyway, I've said more than my piece ;)  I'll leave the resolution up to jfreeman and the moderator.
_agx_Commented:
Hm.. doesn't look like anything was corrected.  Oh well.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.