Skip navigation
cfnew
Currently Being Moderated

need help with display table in cfoutput query

Nov 20, 2011 9:58 AM

Hi,

 

i need to do this form of outputting cfoutput query.

 

<cfquery name="myquery" datasource="mydsn">

select email,phone from mytable

</cfquery>

 

<table>

<tr>

 

<cfoutput query="myquery">

<td>

#myquery.email#<br/>

#myquery.phone#<br/>

</td

</cfoutput>

</tr>

</table>

 

 

but i need output like this like for every 2 records i need new row.

 

Example.

 

Now getting my outpout like this

 

1   2   3   4  5   6  7

 

i want my output like this

 

1   2

3   4

5   6

7

 

Please help me

 

Thanks.

 
Replies
  • Currently Being Moderated
    Nov 20, 2011 5:23 PM   in reply to cfnew

    <cfif currentrow mod 2 is 0 and currentrow lt recordcount></tr><tr></cfif>

     

    Your job is figure out where to put it.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2011 12:49 AM   in reply to cfnew

    Do you really want to display the email and phone of 2 different users on the same row? That doesn't make sense to me. Then again, do you mean, by 2 records per row, that you wish to display the email and phone per user per row? If so, then you require something like this

     

    <table>

    <cfoutput query="myquery">

    <tr>

    <td>

    #myquery.email#

    </td>

    <td>

    #myquery.phone#

    </td>

    </tr>

    </cfoutput>

    </table>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2011 7:59 AM   in reply to cfnew

    <cfquery name="myquery" datasource="mydsn">

    select email,phone from mytable

    </cfquery>

     

    <table>

    <tr>

     

    <cfoutput query="myquery">

    <td>

    #myquery.email#<br/>

    #myquery.phone#<br/>

    </td>

    <cfif currentrow mod 2 eq 0 or currentrow eq recordcount>

         </tr>

    </cfif>

    </cfoutput>

    </table>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2011 9:09 AM   in reply to cp_anil@rediff

    cp_anil@rediff wrote:

     

    <cfquery name="myquery" datasource="mydsn">

    select email,phone from mytable

    </cfquery>

     

    <table>

    <tr>

     

    <cfoutput query="myquery">

    <td>

    #myquery.email#<br/>

    #myquery.phone#<br/>

    </td>

    <cfif currentrow mod 2 eq 0 or currentrow eq recordcount>

         </tr>

    </cfif>

    </cfoutput>

    </table>

    Not quite. Check Dan's suggestion once again.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2011 9:18 AM   in reply to BKBK

    Better yet, don't check my suggestion unless this is an academic exercise.  BKBK gave a better answer.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 30, 2011 7:33 AM   in reply to cfnew

    Sometimes its tricky to get the kind of output you want when you are populating a table with the results of a query, during web application development.

     

    After every two records you want to close the row with </TR> tag, and create a new row in the table using the <TR> tag, which stands for TABLE ROW. Using the MOD function is probably the best way to do this. If the currentrow is divided by 2 with no remainder, then you have to create a new row of data. the equivalent in ColdFusion is <cfif (CurrentRow MOD 2) eq 0>

     

    Here is an example of the code you would need:

     

    <table>

    <tr>

    <cfoutput query="myquery">

    <td>

    #myquery.email#<br/>

    #myquery.phone#<br/>

    </td>

    <!--- if we have outputed two cells of data, close the row and start a new row unless we are at the end of the data --->

    <cfif ((currentrow mod 2) eq 0) or (CurrentRow eq RecordCount)>

         </tr>

         <cfif CurrentRow lt RecordCount> <!--- if we are not at the end of the data, start a new row in the table for data --->

            <tr>

         </cfif>

    </cfif>

    </cfoutput>

    </table>

     

    You have to visualize how the data will be outputed. Hope this helps.

     

    Michael G. Workman

    mworkman@usbid.com

    http://www.usbid.com

    http://ic.locate-ic.com

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 8, 2011 4:13 AM   in reply to cfnew

    Please try this one

     

    <cfscript>

        row=1;

    </cfscript>

    <table>

       

        <cfoutput query="myquery" >

           

           

                <cfif row mod 2 eq 1>

                    <tr>

                    <td>#row#</td><td>#myquery.email#</td><td>#myquery.phone#</td>

                </cfif>

                <cfif row mod 2 eq 0>

                    <td>#row#</td><td>#myquery.email#</td><td>#myquery.phone#</td>

                    </tr>

                </cfif>

                <cfset row=row+1>

           

           

        </cfoutput>

    </table>

     
    |
    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