Skip to main content
August 2, 2012
Question

How to display query result like this

  • August 2, 2012
  • 3 replies
  • 2131 views

I got a query...gives list of names.

i want to display

11.  Peter

12. Jessica

32. Leo

15. Jamie

36. Edward

how i get static number infront of my query result.

static number is not in order.

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    August 3, 2012

    Amm85 wrote:

    I got a query...gives list of names.

    i want to display

    11.  Peter

    12. Jessica

    32. Leo

    15. Jamie

    36. Edward

    how i get static number infront of my query result.

    static number is not in order.

    You could use the function queryAddColumn to add the numbers as a separate column to the query.

    Let us suppose the name of the query is "myQuery". Then you could proceed as follows

    <!---Define your "static" list of numbers --->

    <cfset staticList = "11,12,32,15,36,13,23,14,33,16,44,31,17,34,18">

    <!--- Create an array from the static list. --->

    <cfset staticNrArray = ArrayNew(1)>

    <cfset staticNrArray = listToArray(staticList)>

    <!--- Add the array as a column to the query. --->

    <cfset nColumnNumber = QueryAddColumn(myQuery, "staticNr", "integer", staticNrArray)>

    <!--- Verify whether it works as expected--->

    <cfdump var="#myQuery#">

    The list I have given here has 15 numbers. This will naturally instruct ColdFusion to add a new column named staticNr, having 15 rows. You might like to know that the queryAddColumn function enables padding.

    Here is how it works. Suppose that the query originally had only 8 rows before you added the column(of 15 rows). Then, in the new query, ColdFusion would pad the last 7 rows of the other columns with null values. If the original query  had 20 rows instead, then Coldfusion would pad the last 5 rows corresponding to the staticNr-column with null values.

    tclaremont
    Inspiring
    August 3, 2012

    #QueryName.CurrentRow# ????

    Inspiring
    August 2, 2012

    From where do these numbers come?

    August 2, 2012

    numbers are hardcoded.

    i got 15 numbers...this is fixed.

    query result maybe 14 or 13 or 15 or 12...this result will never exceed 15.

    i want to display query result with hardcoded number.

    11.  Peter

    12. Jessica

    13. Leo

    14. Jamie

    15. Edward

    Inspiring
    August 3, 2012

    Is there any correlation between the number and name?