Specify Query Columns from From

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Specify Query Columns from From

    I want to create a form where a user can select from a drop down box which
    query colums they want to select and in what order.
    The form will be predefined.
    This way the user will select which columns and what order they appear in.
    This is a sample, there are actually 14 columns in the table.


    <table width="700" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><select name="col_1">
    <option value="">Skip</option>
    <option value="stockno">Stockno</option>
    <option value="price">Price</option>
    <option value="cat">Cat</option>
    </select></td>
    <td><select name="col_2">
    <option value="">Skip</option>
    <option value="stockno">Stockno</option>
    <option value="price">Price</option>
    <option value="cat">Cat</option>
    </select></td>
    <td><select name="col_3">
    <option value="">Skip</option>
    <option value="stockno">Stockno</option>
    <option value="price">Price</option>
    <option value="cat">Cat</option>
    </select></td>
    <td><select name="col_4">
    <option value="">Skip</option>
    <option value="stockno">Stockno</option>
    <option value="price">Price</option>
    <option value="cat">Cat</option>
    </select></td>
    </tr>
    </table>

    Honesty I have not clue how to do this?
    I have tried a few things, and nothing to seems to come close.

    Any ideas.
    Thanks
    Johnny

    SincityViper Guest

  2. Similar Questions and Discussions

    1. Arranging Query Columns
      This is my query <cfset Totals = queryNew("TotalPointsEarned,EarnedPointsCost,TotalPointsRedeemed,RedeemedPointsC...
    2. Query of Queries Combinding Columns
      I have two text files that I am using a cfhttp tag to query. I then need to combined the two queries to one query subtracting the "CHANGE" field...
    3. displaying query in 2 columns
      Hi Guys, need your help on this please, I am trying to get the result of my query splited in 2 columns, where in the first column will have my first...
    4. How to span a query into 2 columns
      I have a query that produces a list of products and some of those products are subdivided into groups within the list. I have a query that...
    5. query results in 2 columns?
      I'm struggling to figure out how to do this properly. I have done a mySQL query to extract a list of names, and done a mysql_num_rows to determine...
  3. #2

    Default Re: Specify Query Columns from From

    You can simplify the job by placing your <OPTION> set in a loop. See code
    below.

    <CFLOOP INDEX="i" START="1" STOP="14">
    <SELECT NAME="col_#i#">
    <OPTION VALUE="">Skip
    <OPTION VALUE="stockno">Stockno
    <OPTION VALUE="price">Price
    <OPTION VALUE="cat">CAT
    </SELECT>
    </CFLOOP>

    jdeline Guest

  4. #3

    Default Re: Specify Query Columns from From

    How would this build the report page so that the columns are in the order they
    select.?

    I am trying to build a script where a user can select what columns in a
    database table they want to display in a report.
    In one they may want they columns to appear like this in report.
    stockno,price,model

    in another they may want it like this
    model,price,cat,stockno,wholesale

    Any Ideas

    SincityViper Guest

  5. #4

    Default Re: Specify Query Columns from From

    Refering to my earlier code, replace the "Skip" option line with this: <OPTION
    VALUE="" SELECTED>Skip. Now, if you select the third select box and choose
    "Price", you are assured to get the following passed to your results page:

    col_1: skip
    col_2: skip
    col_3: price
    col_4: skip
    etc.

    So your results page knows column 1 should be price. The following code might
    help:




    <CFLOOP INDEX="i" START="1" TO="14">
    <CFIF Evaluate("col_#i#") IS NOT "skip">
    <!--- do your thing here --->
    </CFIF>
    </CFLOOP>

    jdeline Guest

  6. #5

    Default Re: Specify Query Columns from From

    jdeline,

    I got that part, the part I am looking is the results page. Right now, if I
    pass form vars as the query columns, cfoutput or cfloop will not return the
    query over easily. I say easily because I can not figure it out.

    Any ideas on the results page.
    Johnny

    SincityViper 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