A quick question regarding displaying a formated values from DB

Discussion in 'Programming' started by kimimaro, Mar 14, 2009.

  1. #1
    I have a database which holds the following


    Name - Bob , henry, maurice and Albert


    I know the usual cfoutput query which prints one by one out but now i need it to print in such way as:

    bob - henry
    maurice - albert


    In other words, i want to bring two by two ... two in the same row before <br> into another two.

    Anyone please help me out
     
    kimimaro, Mar 14, 2009 IP
  2. kimimaro

    kimimaro Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Need this urgent before next week thanks.

    I want to printout values in paired manner

    value1 - value 2
    value 3 - value 4
    value 5 - value 6
     
    kimimaro, Mar 15, 2009 IP
  3. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Assuming each "name" is in a separate record, use the MOD operator to create a new <tr> after every two records

    <cfoutput query="someQuery">
    ... output the data ...
    <cfif currentRow MOD 2 EQ 0>
    Two names were displayed. Create a new <tr> here
    </cfif>
    </cfoutput>
     
    cfStarlight, Mar 16, 2009 IP
  4. kimimaro

    kimimaro Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thansk for the valuable feedback starlight! But my format seems a step more to perfection

    Actually i didnt include in the 1st post as to not confuse the readers here but since we already solved 1st case here is teh last one


    my db have two columns which are country and name

    I am arranging it via cfoutput such as


    Country Name

    India Mutusamy - Kiranjit


    Davendran - Muthir

    China Lee - Cheng
    Law - Lei


    In a way it is correct and I group them by country in the cfoutput group = "country" and in the query

    Select *
    from country_name
    order by country

    as so my order is already based on country so can i have another sub order which is by name?

    I wanted to order those list in order from A to Z instead of random.


    Like this



    India Davendran - Kiranjit
    Mutusamy - Muthir

    China Cheng - Law
    Lee - Lei



    PS (Sorry this forum cant let me arrange in a formatted order as now it seems ugly. For short, order 1st by country then 2nd by name )
     
    kimimaro, Mar 16, 2009 IP
  5. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Since they are already ordered by country, you can use cfoutput's "group". (You can add a second order by "name", but it is important that you order by country first).

    
    <cfoutput group="country">
        #country#<br>
        <cfoutput>
            #name#<br>
        </cfoutput>
    </cfoutput>
    
    Code (markup):
    If you also want to display the names in 2 columns you will have to add a manual counter. Unfortunately, currentRow does not work the same when using "group".

    
    <cfoutput group="country">
        #country#<br>
        <cfset counter = 1>
        <cfoutput>
            #name#
            <cfif counter MOD 2 EQ 0>  
               Two names were displayed. Create a new <tr> here
            </cfif>
            <cfset counter = counter + 1>
        </cfoutput>
    </cfoutput>
    
    Code (markup):
     
    cfStarlight, Mar 17, 2009 IP
  6. kimimaro

    kimimaro Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi there thanks again... How do i add a second order?

    It seems error from the cfquery if i include two order in one query.

    Sorry for the newbie question for i am one =s:p
     
    kimimaro, Mar 18, 2009 IP
  7. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry, I don't understand. There are no practical limitations on ordering in a query. Can you post your code and any error message?
     
    cfStarlight, Mar 19, 2009 IP