Professional Web Applications Themes

Order of displaying the data - Coldfusion - Advanced Techniques

Hello, I created a query and can successfully get what I want from MSSQL like this: Date Name Mark 12/1 John 80 12/1 Mary 75 12/1 Steven 60 15/1 Mary 70 15/1 John 100 I wanna use cf code to display my data by a table like: Date 12/1 John 80 Mary 75 Steven 60 (totally 7 columns here) 15/1 Mary 70 John 100 (totally 5 columns here) Is that impossible? I have tried many ways in showing the data but still not work. Please advice. Many thanks...

  1. #1

    Default Order of displaying the data

    Hello,

    I created a query and can successfully get what I want from MSSQL like this:

    Date Name Mark
    12/1 John 80
    12/1 Mary 75
    12/1 Steven 60
    15/1 Mary 70
    15/1 John 100

    I wanna use cf code to display my data by a table like:

    Date
    12/1 John 80 Mary 75 Steven 60 (totally 7 columns here)
    15/1 Mary 70 John 100 (totally 5 columns
    here)

    Is that impossible? I have tried many ways in showing the data but still not
    work. Please advice. Many thanks

    ?? Guest

  2. #2

    Default Re: Order of displaying the data

    Probably not the neatest solution, but I can think of a 'kludge' fix.

    When outputting your query, create a 2 dimensional array. One of the
    dimensions is date, the other is "John 80" or whatever. Then when you've
    finished with your query, use a cfloop to step through your array and output it.

    jakp Guest

  3. #3

    Default Re: Order of displaying the data

    jakp, could you please show me how to put the output of the query into an array?
    ?? Guest

  4. #4

    Default Re: Order of displaying the data

    I've changed your date field name to datefieldname as name is a reserved name :)



    <cfquery name="tablecells" datasource="#yourdsn#">
    select max(maxcols) as total
    from (
    select count(yourdatefield) as maxcols
    from #yourdbtable#
    group by yourdatefield)
    </cfquery>

    <cfquery name="yourquery" datasource="#yourdsn#">
    select yourdatefield, name, mark
    from #yourdbtable#
    order by yourdatefield
    </cfquery>

    <table border>
    <cfoutput><tr><th>Date</th><td
    colspan="#val(tablecells.total*2)#">&nbsp;</tr></cfoutput>
    <tr>
    <cfoutput query="yourquery" group="yourdatefield">
    <th>#yourdatefield#</th>
    <cfset counter=0>
    <cfoutput>
    <td>#name#</td><td>#mark#</td>
    <cfset counter=counter+1>
    </cfoutput>
    <cfif counter lt tablecells.total>
    <td colspan="#val((tablecells.total-counter)*2)#">&nbsp;</td>
    </cfif>
    </tr>
    </cfoutput>
    </table>

    PaulKD Guest

Similar Threads

  1. help displaying data
    By CRC in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 2nd, 09:31 PM
  2. Displaying Foreign Key data
    By Silentking in forum Macromedia ColdFusion
    Replies: 4
    Last Post: March 1st, 11:49 PM
  3. displaying database data
    By trend5 in forum Macromedia Flash
    Replies: 1
    Last Post: July 29th, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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