Query by column name & output

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Query by column name & output

    Hi I have a lot of column names that have a value of 1 or 0. HasRadio 1
    BarLounge 0 IndoorPool 1 etc etc. I am thinking of the best way to query for
    output and have about 40 columns to deal with. <cfif hotel.HasRadio is 1>
    <cfset 1 = Radio> <cfoutput>#1#</cfoutput> <cfelse>'blank space' </cfif> Can
    someone advise me . Thanks

    DuLaus Guest

  2. Similar Questions and Discussions

    1. CFC Query output to XML?
      Good day, Over the past six months or so, I have been developing an application that uses Flash MX 2004, and ColdFusion MX 6.1. I have a number...
    2. Query Struct output
      Hi Experts, I want to Query Out data in list. MyList = john,mary,roger When I make a query Select * from login table where (userid in...
    3. Encoding (UTF-8) and Query Output
      Hello, I am trying to get UTF-8 and Cold Fusion to play nice. So far... things have been nutz! If you can take a look at the 3 files in the...
    4. Organize query output?
      I am doing a query on a MySQL Database and pulling all shops out of our data. That works fine except I want to organize all the shops by state. For...
    5. Column width query
      Sorry this is a repost: Hi, I am wanting to display data in a datagrid with additional header rows above it that categorise some of the main...
  3. #2

    Default Re: Query by column name & output

    The code below gets the column names. Will I have to alias those column names
    and deal with the value of 1 or 0 ? Thanks. <cfquery datasource='travelxml'
    name='gettable'> SELECT TOP 1 * FROM master </cfquery> <cfloop
    list='#gettable.ColumnList#' index='column'> #column#<br> </cfloop>
    </cfoutput>

    DuLaus Guest

  4. #3

    Default Re: Query by column name & output

    Hi DuLaus

    Not really sure what you are asking for here.

    If you want to get the values of the columns you can put an Evaluate around
    the #Column# output.

    See attached Code - hope that is what you were after.

    Zoe

    <!--- loop through all columns in query --->
    <cfloop list="#gettable.ColumnList#" index="column">

    <!--- output column name and its value --->
    Column Name: #column#<BR>
    Column Value: #Evaluate(column)#<BR>

    <!--- show Yes or No for each column depending on its value --->
    #Column#:
    <CFIF Evaluate(column) EQ 1>
    Yes
    <CFELSE>
    No
    </CFIF>

    </cfloop>

    zoeski80 Guest

  5. #4

    Default Re: Query by column name & output

    Hi Zoe, This is the query (columns) below and I am showing one example of
    output in a <cfif> statement. When you look at the column names you will see I
    cannot use these for output as they don't have much meaning. All the data in
    these colums are either 0 or 1. Is there something I can do in the way of a
    structure or array in the application.cfm file and call this when needed by
    using an include statement. I am trying to avoid several dozen <cfif>
    statements... thanks <cfquery datasource='travelxml' name='options'> SELECT
    Id, Name, Address, City, State, StateName, Zip, CountryCode, CountryName,
    Directions, Rating, NumGuestRooms, TwentyFourHrFrontDesk, AMFMClock,
    BarLounge, BanquetFacilities, Beach, BusinessCenter, BarberBeautyShop,
    ChildCare, CoffeeMaker, Concierge, ExpressCheckOut, FreeLocalCalls,
    FreeNewsPaper, FreeParking, FitnessCenter, Fishing, Golf, HairDryerInRoom,
    HCAccessibleRoom, HeatedPool, IndoorPool, LimitedRoomService,
    LaundryValetService, MiiBar, MeetingFacilities, ModemLinesInRoom,
    NonSmokingRooms, OutdoorPool, PetsAllowed, Restuarant, RVTruckParking,
    SafeDepositBox, Shops, Skiing, Spa, Tennis, CourtesyCar, AreaAttraction1,
    AreaAttraction2, AreaAttraction3, AreaAttraction4, AreaAttraction5,
    AreaAttraction6, NearbyRestuarant1, NearbyRestuarant2, NearbyRestuarant3,
    NearbyRestuarant4, NearbyRestuarant5, NearbyRestuarant6, NumMeetingRooms,
    CapacityMeetingRooms,DescriptionMeetingRooms, LowStandardRoomRate,
    HighStandardRoomRate, AmericanExpressAccepted, DiscoverAccepted,VisaAccepted,
    MastercardAccepted, CarteBlancheAccepted, DinersClubAccepted, JCBAccepted,
    NoCreditCardsAccepted,YearBuilt, YearRenovated, OtherFeatures, FirePlaceRooms,
    FreeContinentalBreakfast FROM master WHERE Id = 71138 </cfquery> <cfif
    #options.TwentyFourHrFrontDesk# eq 1> 24 Hour Front Desk </cfif>

    DuLaus Guest

  6. #5

    Default Re: Query by column name & output

    You could rename each of the columns that is a feature to a common name and
    include the description in your SQL. Then create a list of the fields you want
    to evaluate and loop through them.

    Here is a small example using part of your SQL:


    <cfquery datasource="travelxml" name="options">
    SELECT Id,
    Name,
    Address,
    City,
    TwentyFourHrFrontDesk as F1, '24 Hour Front Desk' as F1desc,
    AMFMClock as F2, 'AM / FM Clock' as F2desc,
    BarLounge as F3, 'Bar Lounge' as F3desc,
    BanquetFacilities as F4, 'Banquet Facilities' as F4desc,
    Beach as F5, 'Beach' as F5desc
    FROM master
    WHERE Id = 71138
    </cfquery>

    <cfset featurelist = "F1,F2,F3,F4,F5">

    <cfoutput query="options">
    #options.Name#, #options.Adress#, #options.City#<br>
    <cfloop index="i" list="#featurelist#">
    <cfif evaluate("options.#i#") eq 1>
    #evaluate("options.#i#desc")#<br>
    </cfif>
    </cfloop>
    <hr>
    </cfoutput>

    eastinq Guest

  7. #6

    Default Re: Query by column name & output

    Hi easting

    Thanks for your reply.

    That will work...

    Cheers
    DuLaus Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139