Looping over query details

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • worldspy
    New Member
    • Sep 2007
    • 2

    Looping over query details

    Hi guys,

    I don't know whether this is feasible or not. But here is my problem

    I have a session variable which has database field names in a particular order and this variable is generated dynamically, I dont know what is in that variable and in what order. What I have to do is display my results in the order they are in the session variable. So for example if my session varialbe contains

    session.sv = "Id,Name,Addres s,Phone,City,Lo cation"

    I am using this directly in my query as

    select #session.sv# from details

    And I want to display the records only in that particular order i.e Id, Name, Address, Phone, City and Location, this order is dynamic. So It can be City first, Address second etc...

    Hope someone can tell me how to solve this issue.

    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    That's just a list, so loop over it as you would a list.

    Comment

    • Shift4SMS
      New Member
      • Feb 2007
      • 14

      #3
      Just in case you need an example of what acoder was saying:

      [CODE=cfm]<cfset session.sv = "Id,Name,Addres s,Phone,City,Lo cation">

      <cfquery name="qResults" datasource="#ds #" username="#un#" password="#pw#" >
      select #session.sv# from details
      </cfquery>

      <cfoutput>
      <table>
      <tr>
      <cfloop index="fieldnam e" list="#session. sv#">
      <th>#fieldname# </th>
      </cfloop>
      </tr>
      <cfloop query="qResults ">
      <tr>
      <cfloop index="fieldnam e" list="#session. sv#">
      <td>qResults[fieldname][qResults.Curren tRow]#</td>
      </cfloop>
      </tr>
      </cfloop>
      </table>
      </cfoutput>[/CODE]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Thanks for the example. Makes it a lot easier to understand.

        Comment

        • worldspy
          New Member
          • Sep 2007
          • 2

          #5
          Thanks a bunch for responding with a code hint, it works great :-)

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Glad to hear you got it working. Post back anytime if you have more queries.

            Comment

            Working...