Skip to main content
Inspiring
October 17, 2008
Question

How can I add a comma ?

  • October 17, 2008
  • 2 replies
  • 425 views
I am using the following code to produce output :

<cfoutput query="qryView" group="materialNumber">
<tr>
<td class="TitleText">#materialNumber#</td>
<td class="TitleText">#purchaseOrder#</td>
<td class="TitleText"><cfoutput>#qryView.serialNumber#  </cfoutput></td>
<td class="TitleText">#qryView.quantity#</td>
<td class="TitleText">#dollarformat(qryView.unitValue)#</td>
</tr>
</cfoutput>

For the serial number line, it outputs one serial number after another. I want to add a comma at the end of each serial number to separate them, but if I add the comma, it will also add a comma to the last number, which is not what I want. Since I did not know how to do this, I just added two   to separate the serial numbers. I tried to use valuelist but it duplicates the serial numbers for each material number. This code produces the output I want, except for the comma to separate each serial number.

How can this be done ?
    This topic has been closed for replies.

    2 replies

    Inspiring
    October 17, 2008
    quote:

    Originally posted by: trojnfn
    I am using the following code to produce output :

    <cfoutput query="qryView" group="materialNumber">
    <tr>
    <td class="TitleText">#materialNumber#</td>
    <td class="TitleText">#purchaseOrder#</td>
    <td class="TitleText"><cfoutput>#qryView.serialNumber#  </cfoutput></td>
    <td class="TitleText">#qryView.quantity#</td>
    <td class="TitleText">#dollarformat(qryView.unitValue)#</td>
    </tr>
    </cfoutput>

    For the serial number line, it outputs one serial number after another. I want to add a comma at the end of each serial number to separate them, but if I add the comma, it will also add a comma to the last number, which is not what I want. Since I did not know how to do this, I just added two   to separate the serial numbers. I tried to use valuelist but it duplicates the serial numbers for each material number. This code produces the output I want, except for the comma to separate each serial number.

    How can this be done ?

    Change this:
    <cfoutput>#qryView.serialNumber#  </cfoutput></td>
    to this:
    <cfoutput>#qryView.serialNumber#
    <cfif currentrow lt recordcount>
    <cfif materialNumber[currentrow] is materialNumber[currentrow + 1]>
    ,
    </cfif>
    </cfif>
    </cfoutput>


    Inspiring
    October 17, 2008
    how about something like this?

    <cfoutput query="qryView" group="materialNumber">
    <tr>
    <td class="TitleText">#materialNumber#</td>
    <td class="TitleText">#purchaseOrder#</td>
    <td
    class="TitleText">#qryView.serialNumber#<cfif currentrow lt
    qryview.recordCount>,</cfif></td>
    <td class="TitleText">#qryView.quantity#</td>
    <td class="TitleText">#dollarformat(qryView.unitValue)#</td>
    </tr>
    </cfoutput>

    may not be what you want though.. i am not sure how you are trying to
    show the serial number list, with the nested cfoutputs.

    if each output shows the full list, try a cfloop like this

    <cfset loopct = 0>
    <cfloop query="qryView">
    #qryview.serialNumber#<cfif loopct lt qryview.recordcount>,</cfif>
    </cfloop>


    other ways include the useful listAppend() function... just depends on
    what you want the output to look like, and how you plan to use it


    Michael Evangelista, Evangelista Design
    Web : www.mredesign.com Blog : www.miuaiga.com
    Developer Newsgroups: news://forums.mredesign.com

    trojnfn wrote:
    > I am using the following code to produce output :
    >
    > <cfoutput query="qryView" group="materialNumber">
    > <tr>
    > <td class="TitleText">#materialNumber#</td>
    > <td class="TitleText">#purchaseOrder#</td>
    > <td
    > class="TitleText"><cfoutput>#qryView.serialNumber#  </cfoutput></td>
    > <td class="TitleText">#qryView.quantity#</td>
    > <td class="TitleText">#dollarformat(qryView.unitValue)#</td>
    > </tr>
    > </cfoutput>
    >
    > For the serial number line, it outputs one serial number after another. I want
    > to add a comma at the end of each serial number to separate them, but if I add
    > the comma, it will also add a comma to the last number, which is not what I
    > want. Since I did not know how to do this, I just added two   to separate
    > the serial numbers. I tried to use valuelist but it duplicates the serial
    > numbers for each material number. This code produces the output I want, except
    > for the comma to separate each serial number.
    >
    > How can this be done ?
    >