Skip to main content
March 16, 2009
Answered

Query Output

  • March 16, 2009
  • 6 replies
  • 602 views
I have a table that in an effort to condense space has a feature_ID, features_description, & feature_item_number. The feature_item_number is the same for each product but the other to change so for example for product a you might have:

Feature_ID - 1
Features_description - Easy to use
feature_item_number - a

Feature_ID - 1
Features_description - Light Weight
feature_item_number - a

Using the code attached how do I get the output to step to the next row and not just keep repeating the first line it finds in the database?
    This topic has been closed for replies.
    Correct answer
    Figured it out this worked:

    <tr>
    <td width="135" background="images/middle_left.jpg" class="left_column"><p> </p></td>
    <td width="350" background="images/middle_right.jpg"> </td>
    </tr>
    <cfoutput query="GetProductFeatures" startrow="1" maxrows="6">
    <tr>
    <td width="135" background="images/middle_left.jpg" class="left_column"><p>Features #GetProductFeatures.currentRow# </p></td>
    <td width="350" background="images/middle_right.jpg"><cfinput type="text" name="feature#GetProductFeatures.currentRow#" maxlength="100" value="#features_description#"><cfinput type="hidden" name="features#GetProductFeatures.currentRow#" value="#features_ID#"></td>
    </tr></cfoutput>

    6 replies

    Inspiring
    March 17, 2009
    when you use <cfoutput> or <cfloop> with QUERY attribute you do not need
    to reference query row - the output iterates over the query rows
    automatically.

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Matt Gifford
    Participating Frequently
    March 16, 2009
    Yes, that would work, but why over complicate it?
    You had everything in the first example, you just needed to include the loop index in the square brackets (as mentioned above) which gets the current row and is a lot neater to use.
    Correct answer
    March 16, 2009
    Figured it out this worked:

    <tr>
    <td width="135" background="images/middle_left.jpg" class="left_column"><p> </p></td>
    <td width="350" background="images/middle_right.jpg"> </td>
    </tr>
    <cfoutput query="GetProductFeatures" startrow="1" maxrows="6">
    <tr>
    <td width="135" background="images/middle_left.jpg" class="left_column"><p>Features #GetProductFeatures.currentRow# </p></td>
    <td width="350" background="images/middle_right.jpg"><cfinput type="text" name="feature#GetProductFeatures.currentRow#" maxlength="100" value="#features_description#"><cfinput type="hidden" name="features#GetProductFeatures.currentRow#" value="#features_ID#"></td>
    </tr></cfoutput>
    Matt Gifford
    Participating Frequently
    March 16, 2009
    Ok, the post reply didnt pick up the changes I had written (try again)

    What you need to do is to:

    1) sort out the cfoutput tags. Perhaps put them surrounding the cfloop (as above)
    2) to get the variables you need, add the index, so instead of #GetProductFeatures.features_description# you would attach the index variables (i, in your case) inside square brackets at the end of your query variables

    #GetProductFeatures.features_description[ i ]#
    Matt Gifford
    Participating Frequently
    March 16, 2009
    Hi PopcornCoder

    To get the details for each row, you need to add the loop index to the end of the query/variables being dislpayed, otherwise you would only receive the top values

    Try this:

    <cfoutput>
    <cfloop from="1" to="6" index="i">
    <tr>
    <td width="135" background="images/middle_left.jpg" class="left_column"><p>Features #i# </p></td>
    <td width="350" background="images/middle_right.jpg">
    <cfinput type="text" name="feature#i#" maxlength="100" value="#GetProductFeatures.features_description #">
    <cfinput type="hidden" name="features#i#" value="#GetProductFeatures.features_ID
    #"></td>
    </tr>
    <cfset i = i + 1>
    </cfloop>
    Inspiring
    March 16, 2009
    PopcornCoder wrote:
    >
    > Using the code attached

    With a great deal of unnecessary difficulty.

    Take a look at the <cfoutput...> documentation and play close attention
    to the group property and nesting <cfoutput...> tags. This feature is
    built just for this type of functionality.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_m-o_16.html#1101659