• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

need help with display table in cfoutput query

New Here ,
Nov 20, 2011 Nov 20, 2011

Copy link to clipboard

Copied

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.

TOPICS
Getting started

Views

2.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 20, 2011 Nov 20, 2011

Copy link to clipboard

Copied

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

Your job is figure out where to put it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2011 Nov 21, 2011

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2011 Nov 24, 2011

Copy link to clipboard

Copied

<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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2011 Nov 24, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2011 Nov 24, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 30, 2011 Nov 30, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2011 Dec 08, 2011

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation