EllensburgMoose
EllensburgMoose

Reputation: 39

ColdFusion cfselect display two query columns

I'm trying to display the results of a query, but I'm having a hard time combining two values that the query produces... Here's the query I have

    <cffunction name="getStudentData"  returntype="query">
    <cfargument name="nameVar" type="string" required="yes">
    <cfargument name="timeframe" type="numeric" required="yes">

    <cfquery datasource="#Application.hds#" name="gsd">
    select (s.lastname + ', ' + s.firstname) as StudData,
    ('[' + r.hallname + ' ' + r.roomnumber + ']')  as roomdata,
     s.studentnumber
    from tblstudents s left join 
    (select h.hallname, ra.roomnumber, studentid 
    from tblroomassignments ra, tblhalls h
    where ra.TimeFrame = #Arguments.timeframe# 
    and ra.hallid = h.hallid) r
    on s.studentid = r.studentid
    where s.lastname like '#Arguments.nameVar#%'
    </cfquery>
    <cfreturn #gsd#>
    </cffunction>

What I'm trying to figure out is how to display StudData+' '+roomdata IF they both exist together since some students won't have a room assigned to them. (I'm just trying to produce a list of students that have a dorm/room assigned to them. In my cfselect...

<cfselect name="RecipientName"
          query="studentdata"
          display="StudData+' '+roomdata"???????
          value="studentnumber">
</cfselect>

I don't know how to get StudData and roomdata in the display attribute without the page giving me an query column error. I'm very new to coldfusion and it's my understanding that you can only display one variable? Is there a way to combine StudData and roomdata into a variable and then display that variable?

Anyone have any ideas? Could this be simplified? Hope this all makes sense!

Upvotes: 3

Views: 1011

Answers (1)

Fish Below the Ice
Fish Below the Ice

Reputation: 1271

I wouldn't use a cfselect at all.

<select name="RecipientName">
  <cfoutput query="studentdata">
    <option value="#studentnumber#">#StudData# #roomdata#</option>
  </cfoutput>
</select>

If you really want to use cfselect, then I'd concatenate the columns in your query.

StudData + roomdata AS expanded_student_data

...

<cfselect name="RecipientName"
  query="studentdata"
  display="expanded_student_data"
  value="studentnumber"
>
</cfselect>

Upvotes: 4

Related Questions