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

Display result of 1st row only from a query

Engaged ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

Hi. I have a search page that searches on a part number. It displays results into a table dynamically. The rows are ordered by a field called ECID. It's just an auto number field I have set up in Access. There are different numbers of rows that are displayed each time a search is done depending on what was searched. I would like to only show the first result for a different search I want to do. How do I do that? I don't have a cfoutput query. Instead I'm using a cfloop query. I can't remember the reason, but I think I needed to use this. I know in a cfoutput query I could use the maxrows function, but I can't use it in a cfloop query. Does anyone know how to get only the first row to display? Is there some other way to make this work? My cfloop query looks like this: <cfloop query="MainActionSearch"> Thanks.

Andy

Views

2.0K

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
Engaged ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

Do you really need to loop it if you just want to show one row?  How about just displaying the first row using associative array notation?  Here is a simple example that creates a query and displays the first row only:

<cfscript>

  q = queryNew("column,column2");

  queryAddRow(q, 2);

  querySetCell(q, "column", "data1", 1);

  querySetCell(q, "column2", "data2", 1);

  querySetCell(q, "column", "data3", 2);

  querySetCell(q, "column2", "data4", 2);

</cfscript>

<!--- output the first row --->

<cfoutput>#q.column[1]# #q.column2[1]#</cfoutput>

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
Engaged ,
Jul 09, 2015 Jul 09, 2015

Copy link to clipboard

Copied

LATEST

Nic,

   Thanks. I created another output query page that used cfoutput query instead of the cfloop. I kept the cfloop on the other output page since my other pages require that. I am using this output page with the cfloop as a template for my other search result pages. I used some javascript for creating 2 buttons to go to the 2 different results pages depending on which one the user clicked.

Andy

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