[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

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>
0
jfreeman2010
Asked:
jfreeman2010
  • 10
  • 8
  • 2
6 Solutions
 
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>
0
 
_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>
0
 
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>

   
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
_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>
0
 
srikanthmadishettiCommented:
@agx

Again an mid air  collision between our comments  :)
0
 
_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>
0
 
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>
0
 
_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
0
 
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>
0
 
jfreeman2010Author Commented:
Thank you for helping!!!
0
 
_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>
0
 
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
0
 
_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
       ....

0
 
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
0
 
_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





0
 
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
0
 
_agx_Commented:
That just reiterates my correct answer which was given much earlier http:#a36945171 . The 2nd comment in fact.
0
 
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 .
0
 
_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.
0
 
_agx_Commented:
Hm.. doesn't look like anything was corrected.  Oh well.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 10
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now