Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get particular Row in a query variable using ColdFusion?

Take the following query example:

<cfquery name="Test" Datasource = "TestDB">
    Select * from Table_Test
</cfquery>

Assume that the "Test" query returns 10 rows. I want to show single row on current time.

Note: I do not want to change the SQL statement.

like image 649
Mohanrajan Avatar asked Oct 27 '14 11:10

Mohanrajan


2 Answers

If you know your row number, Test.columnName[RowNumber] will show you the value of the columnName in specified row number.

like image 142
CFML_Developer Avatar answered Jan 03 '23 14:01

CFML_Developer


If you want one random row from the query:

    <cfset start = randRange(1, Test.recordCount)>
    <cfoutput>
        #Test.name[start]#&nbsp;#Test.email[start]#<br>
    </cfoutput>

No need to loop.

NOTE: It is more efficient to modify the query to get a random row.

How to request a random row in SQL?

like image 42
Scott Jibben Avatar answered Jan 03 '23 13:01

Scott Jibben