Skip navigation
Amm85
Currently Being Moderated

How to display query result like this

Aug 2, 2012 1:14 PM

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.

 
Replies
  • Currently Being Moderated
    Aug 2, 2012 2:33 PM   in reply to Amm85

    From where do these numbers come?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 7:04 PM   in reply to Amm85

    Is there any correlation between the number and name?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 8:19 AM   in reply to Amm85

    #QueryName.CurrentRow# ????

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 9:54 AM   in reply to Amm85

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points