Populating Dynamic Table

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default Populating Dynamic Table

    I am putting information about events into an event calendar for any given
    date with each date spanning, days, weeks, or months with some dates containing
    more than one event. I want to create a dynamic table (3 columns, single row)
    on my home page that pulls event data from my database with the three most up
    and coming events always populating the table regardless of the span of time
    between dates. I am at a loss at how to do this.

    HMOKeefe Guest

  2. Similar Questions and Discussions

    1. cfloop dynamic variable populating
      Hello all, I have what I suspect is a basic question about cfloop. I have a simple database of interest groups + terms of reference (tor) for...
    2. Populating dynamic checkboxes using query data
      I am building an update form for a table that has checkbox data. How can I populate the checkboxes with data from the table so users can see the...
    3. Dynamic Table ?
      Sure it's possible .. there is an Excel driver that works pretty much like the Access driver in the MDAC. That said .. I would personally import it...
    4. How to create a table with dynamic table name
      <html><div style='background-color:'><DIV> <DIV class=Section1> <P class=MsoNormal style="mso-layout-grid-align: none"><FONT face="Times New Roman"...
    5. Dynamic Table with Dynamic LinkButtons
      Looks like I'm not the only one to come across this. Found a post 9 months old that deals with the same thing. Here's the fix: Add line:...
  3. #2

    Default Re: Populating Dynamic Table

    Hopefully when you say "dynamic table" you mean html table and not database table.

    Once you pull the event data, you can simply display it. There is no need to put it into another table.
    Dan Bracuk Guest

  4. #3

    Default Re: Populating Dynamic Table

    Yes...this is a dynamic HTML table on my Home Page, but my difficulty is
    refreshing the table from the events database so that the three most up and
    coming events show up in this three-column table. For instance I have event
    data for date1, date2, date3, date4, and date5. I want date1, date2, date3 data
    to show up in the HTML table, and when date1 has expired, I want date2, date3,
    and date4 data to populate the table and so on...

    HMOKeefe Guest

  5. #4

    Default Re: Populating Dynamic Table

    You want to write a query that selects events in the future, sorted by date,
    and returns only three records. The specifics depend on your database software
    and table structure.

    It would be something like,
    select top 3 field1, field2, etc
    from etc
    where event_date > current_date
    order by event_date

    Dan Bracuk Guest

  6. #5

    Default Re: Populating Dynamic Table

    Hmmm...can't seem to make that work. Here my code:



    <cfparam name="URL.CurrentDate" default="1">
    <cfquery name="eventList" datasource="Functions">
    SELECT Title, OneLineDesc, Description, EventDate, EventTime, CategoryID,
    EventTimeTo, Name FROM Events5051 WHERE EventDate>'#URL.CurrentDate#' ORDER BY
    EventDate ASC
    </cfquery>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Events</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    <!--
    .style1 {color: #FFFFFF}
    -->
    </style>
    </head>

    <body>
    <table width="800" border="1" cellpadding="2">
    <tr>
    <td bgcolor="#6666FF"><cfoutput>#eventList.CategoryID# </cfoutput>
    <p><cfoutput>#LSDateFormat(eventList.EventDate,'MM MM DD,
    YYYY')#</cfoutput><br />

    <cfoutput>#eventList.EventTime#</cfoutput>-<cfoutput>#eventList.EventTimeTo#</cf
    output></p>
    <p><cfoutput>#eventList.OneLineDesc#</cfoutput></p>
    <p>&quot;<cfoutput>#eventList.Title#</cfoutput>&quot;</p>
    <p>Organized by <cfoutput>#eventList.Name#</cfoutput><br />
    </p></td>
    <td><p><cfoutput>#eventList.CategoryID#</cfoutput> </p>
    <p><cfoutput>#LSDateFormat(eventList.EventDate,'MM MM DD,
    YYYY')#</cfoutput><br />

    <cfoutput>#eventList.EventTime#</cfoutput>-<cfoutput>#eventList.EventTimeTo#</cf
    output></p>
    <p><cfoutput>#eventList.OneLineDesc#</cfoutput></p>
    <p>&quot;<cfoutput>#eventList.Title#</cfoutput>&quot;</p>
    <p>Organized by <cfoutput>#eventList.Name#</cfoutput></p></td>
    <td bgcolor="#6666FF"><p><cfoutput>#eventList.Category ID#</cfoutput> </p>
    <p><cfoutput>#LSDateFormat(eventList.EventDate,'MM MM DD,
    YYYY')#</cfoutput><br />

    <cfoutput>#eventList.EventTime#</cfoutput>-<cfoutput>#eventList.EventTimeTo#</cf
    output></p>
    <p><cfoutput>#eventList.OneLineDesc#</cfoutput></p>
    <p>&quot;<cfoutput>#eventList.Title#</cfoutput>&quot;</p>
    <p>Organized by <cfoutput>#eventList.Name#</cfoutput></p></td>
    </tr>
    </table>
    </body>
    </html>

    HMOKeefe Guest

  7. #6

    Default Re: Populating Dynamic Table

    HMOKeefe,

    Assuming "EventDate" is a date/time column (ie. not a text/varchar type
    column)....

    1. Since you are simply comparing the "eventDate" against the curent date,
    this is not needed.
    <cfparam name="URL.CurrentDate" default="1">

    2. You query does not limit the number of results returned. Use the sql
    operator TOP (or your database's equivalent) with an ORDER BY clause to limit
    the number of results to 3 records. Assuming #URL.CurrentDate# is a valid date
    in "mm/dd/yyyy" format, try:


    ---- not tested
    SELECT TOP 3 EventDate, ....other columns...
    FROM yourTable
    WHERE eventDate >= #CreateODBCDate(now())#
    ORDER BY EventDate ASC

    * Note - This will include any events dated today.


    3. Your current output code will display the first record in the query 3
    times. Get rid of all those separate cfoutputs tags and use (1) cfoutput tag
    with the query attribute to ensure that all three records are displayed.



    <table width="800" border="1" cellpadding="2">
    <tr>
    <cfoutput query="eventList">
    <td <cfif currentRow MOD 2 neq 0>bgcolor="##6666FF"</cfif>>
    #LSDateFormat(EventDate,'MMMM DD, YYYY')#
    ... other columns ...
    </td>
    </cfoutput>
    </tr>
    </table>

    mxstu Guest

  8. #7

    Default Re: Populating Dynamic Table

    Great! This works. But could you comment the following code you put in. If I
    understood what it was actually doing, I could figure out how to get white text
    onto the colored background:

    <cfif currentRow MOD 2 neq 0>bgcolor="##6666FF"</cfif>>

    In any case thanks for your help!

    HMOKeefe Guest

  9. #8

    Default Re: Populating Dynamic Table

    > <cfif currentRow MOD 2 neq 0>bgcolor="##6666FF"</cfif>>
    Well, I thought in your original code you were alternating the background
    color for the different cells. The code above just says if this is an odd
    numbered row (1,3, etc), use the background color "6666FF".

    mxstu Guest

  10. #9

    Default Re: Populating Dynamic Table

    Now I am a bit confused. I only have one row, but three columns. How does
    currentRow work if there is only one? Even so I got the right output. Where
    would I put the font color information in this statement for the alternating
    colored columns

    HMOKeefe Guest

  11. #10

    Default Re: Populating Dynamic Table

    "CurrentRow" is the query row number. This number is not related to the number
    of rows in the html table. In your cfoutput loop, #CurrentRow# reflects the
    data row number being output. So in the first loop, #currentRow# is (1), in the
    second loop #currentRow# is (2), etc.

    CurrentRow | EventDate
    -------------------------------------
    1 | 10/15/2005
    2 | 10/22/2005
    3 | 10/28/2005

    <table width="800" border="1" cellpadding="2">
    <tr>
    <cfoutput query="eventList">
    <td <cfif currentRow MOD 2 neq 0>bgcolor="##6666FF"</cfif>>
    #LSDateFormat(EventDate,'MMMM DD, YYYY')#
    ... other columns ...
    </td>
    </cfoutput>
    </tr>
    </table>

    mxstu Guest

  12. #11

    Default Re: Populating Dynamic Table

    To answer the second part of that question, although white text isn't always
    the best choice from a usuability standpoint, one way would be be to use css
    with the MOD check. For example, if you had a class called "whiteText":

    <p <cfif currentRow MOD 2 neq 0>class="whiteText"</cfif>> .... query data
    values here </p>



    mxstu 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