Skip to main content
Inspiring
July 9, 2015
Question

Display result of 1st row only from a query

  • July 9, 2015
  • 1 reply
  • 2435 views

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

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 9, 2015

    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>

    Inspiring
    July 9, 2015

    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