Skip to main content
August 15, 2008
Question

Dynamic Column output

  • August 15, 2008
  • 6 replies
  • 779 views
I have been struggling with something that I am not sure that I can do. I have a database table with 84 Columns. The rows represent projects that are constantly being added and updated. Each column represents a weekending date with the headings of W1(being week 1), W2(being week 2), W84(being week 84), ...etc. Each product has various durations so not all columns are populated. Some may only have a duration of a couple of weeks. I have a form that I want to use to update these columns. Below I have given an example of what I am trying to do. Obviously the Value attribute will not work but you can get the idea of what i am trying to accomplish. The weekday variable changes in an index loop.

<cfset weekday = 1>

<td align="right" width="70">
<CFINPUT TYPE="Text"
NAME="W#Weekday#"
SIZE="5"
validate="float"
value="#W#Weekday##"
MAXLENGTH="10">
</td>

any ideas?
    This topic has been closed for replies.

    6 replies

    Known Participant
    August 16, 2008
    you have 80 something variables for each project?
    Inspiring
    August 15, 2008
    Dan Bracuk wrote:
    > Normalize your database and you won't have problems like this.

    + 1

    Not to mention eighty four columns is a very wide table.
    August 16, 2008
    Unfortunately this is as good as it gets. I may have four to five thousand projects(rows) a year and I must track some of them for over a year to two years. Each column is a week. If you can brain up a better plan believe me I am up for it. Fire away.

    PS the array notion helped. I must now simply work with my loops. Thanks for the help.
    Inspiring
    August 17, 2008
    quote:

    Originally posted by: chrispilie
    Unfortunately this is as good as it gets. I may have four to five thousand projects(rows) a year and I must track some of them for over a year to two years. Each column is a week. If you can brain up a better plan believe me I am up for it. Fire away.


    Learn data modelling. That's a better plan.
    Inspiring
    August 15, 2008
    Normalize your database and you won't have problems like this.
    Inspiring
    August 15, 2008
    > Does this make better sense?

    Perhaps array notation would help. It can be used to access query columns dynamically.

    #queryName["W"& WeekDay][RowNumber]#
    BKBK
    Community Expert
    Community Expert
    August 17, 2008
    What I am trying to accomplish is for this:
    W#Weekday# to equal "W1"
    but in the form. This won't work:
    value="queryname.W#Weekday#"
    it just displays

    queryname.W1

    Does this make better sense?


    Yes it does. The evaluate function might be slow and complex, but would work here. For example,

    value="#evaluate('queryname' & '.' & 'W#Weekday#')#"

    August 15, 2008
    Let me give an example:

    Row 1 is a project named "Crude Oil Demolition".Column 1 is W1 (week one) which has a value of "280" (hours of work).. Column 2 is W2 (week 2) which has a value of "320" (hours of work). Without going into to much detail, there are 20 more weeks of work (20 more columns) with hours assigned to them. There are constantly jobs being added to this table with hours being allocated to each week of work. Some jobs may have 3 weeks of work and some may have 80 weeks.The user sets up the job in another form with a duration(length) in weeks. When they come to this form to populate the values of the hours per week table, the form is looped (index loop) by the number of weeks of duration that the user has indicated in the other form. They then insert the hours per week in the cfinput form element. Once they do this they will submit the form. Now they may have to come back and change these hours so there will be a need for the form to dynamically display the current value and allow for change. Each column name has a W then a number... hence my logic of

    W#Weekday#

    The W will never change but the value of weekday will change with the index loop. What I am trying to accomplish is for this:

    W#Weekday# to equal "W1"

    but in the form. This won't work:

    value="queryname.W#Weekday#"

    it just displays

    queryname.W1

    Does this make better sense?
    August 15, 2008
    I dont fully understand your question.. You want to "output" only certain columns into the form?

    Do you want to only update certain columns?