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

simple cfquery question - amateur level

New Here ,
Jul 24, 2010 Jul 24, 2010

Hello all,

making some simple changes to my website

there is already a database running with plenty of cfloop query

question is this:

this code below retrieves the cake name (#cake_name#) for row 1 in the database, but its using a loop

<cfloop query="cake_query" STARTROW="1" ENDROW="1">

#cake_name#

</cfloop>

how do i do this without using a loop?

i thought it ould be as simple as this:

<cfquery="cake_query" ROW="1">

</cfquery>

but apparently not...

also at the top of the code, there is already this code below, which i know works with the loop queries, im assuming i dont need to change for single row queries?

<cfquery name="cake_query" datasource="#request.datasource#"
username="#request.username#" password="#request.password#">
SELECT * FROM gce_cakes where cake_active = 1 ORDER BY cake_number
</cfquery>

Thank you in advance to anyone that can help

TOPICS
Database access
907
Translate
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

correct answers 1 Correct answer

LEGEND , Jul 24, 2010 Jul 24, 2010

If you want to access any given element of a query, irrespective of how many rows it has, the format is:

queryName.columnName[rowNumber]

And if you want to output it:

<cfoutput>#queryName.columnName[rowNumber]#</cfoutput>

As for the <cfquery> question... <cfquery> is for sending SQL strings and params to a DB driver, and converting what it returns into a recordset (misguidedly referred to as a "query" quite often in CF parlance & tag attributes).  <cfquery> doesn't care how many rows are returned fr

...
Translate
LEGEND ,
Jul 24, 2010 Jul 24, 2010

If you want to access any given element of a query, irrespective of how many rows it has, the format is:

queryName.columnName[rowNumber]

And if you want to output it:

<cfoutput>#queryName.columnName[rowNumber]#</cfoutput>

As for the <cfquery> question... <cfquery> is for sending SQL strings and params to a DB driver, and converting what it returns into a recordset (misguidedly referred to as a "query" quite often in CF parlance & tag attributes).  <cfquery> doesn't care how many rows are returned from the DB: 0... 1... more than one... it just returns a recordset with that many rows in it.

Make sense?


--

Adam

Translate
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 ,
Jul 24, 2010 Jul 24, 2010
LATEST

Adam,

Thank you! your code has made perfect sense and works.

also what you said about cfquery sort of makes sense, im hoping i can get by on my LIMITED knowledge till i can afford to

get the wholesite rebuilt professionally.

Thanks again, you have really saved me hours of time.

Translate
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