ColdFusion cfselect displays two query columns

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

    <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 to display StudData + '' + roomdata if they both exist together, as some students won't have a room allocated to them. (I am just trying to create a list of students who have a dorm / room assigned to them.In my cfselect ...

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

      

I dont know how to get StudData and roomdata data in display attribute without page giving me query column error. I'm very new to coldfusion and I understand that you can only display one variable? Is there a way to combine StudData and roomdata data into a variable and then display that variable?

Does anyone have any idea? Could this be simplified? Hope this all makes sense!

+3


source to share


1 answer


I wouldn't use it at all cfselect

.

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

      



If you really want to use cfselect

, I would concatenate the columns in your query.

StudData + roomdata AS expanded_student_data

...

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

      

+4


source







All Articles