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

Adding multiple db columns to ValueList()?

Participant ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

I'm looping over a query inside cfscript. I need to place the results inside of another loop so I'm storing the results of the first query inside of a value list and then displaying that value list inside the second query results.

The only problem is I need to put more than one db column side by side in the value list

My code below...I need to add more columns beside the fname from the getstadd query. Is this even possible?

...

for (

intRow = 1 ;

intRow LTE getstaff.RecordCount ;

intRow = (intRow + 1)

)

{ }

var allstaff = "<span class='staffoncal'>" & ValueList(getstaff.fname, "<br />") & "</span>";

outString = outString & "height='#height#'>" & allstaff & "<p />" & allevents & "</td> ";

TOPICS
Advanced techniques

Views

2.7K

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

correct answers 1 Correct answer

Valorous Hero , Dec 01, 2011 Dec 01, 2011

If you want to save the results to a variable, simply concatenate the values inside your for loop instead.  But there is no need to create extra arrays. Just access the query columns with array notation:

yourVar = "";

for (intRow = 1 ;intRow <= getstaff.RecordCount ;intRow = intRow + 1)

{

    yourVar = yourVar & getStaff.fnames[intRow] & " " & getStaff.lnames[intRow] & "....");

}

Votes

Translate

Translate
Community Expert ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

Valuelist is a function of just one column. As far as I know, you cannot apply it to multiple columns simultaneously.

Anyway, converting from the valuelist to an array will give you more freedom. You will then have individual arrays which you can concatenate, style or display in any way you want. Here follows an example

// array to hold list of first names

var fnames = arrayNew(1);

// array to hold list of corresponding last names

var lnames = arrayNew(1);

// initialize the arrays

var isSet = arraySet(fnames, 1,getstaff.recordCount, "")>

var isSet = arraySet(lnames, 1,getstaff.recordCount, "")>

// set the array entries

fnames = listToArray(valueList(getstaff.fname));

lnames = listToArray(valueList(getstaff.lname));

// concatenate fname and lname into full name and display

for (

intRow = 1 ;

intRow LTE getstaff.RecordCount ;

intRow = (intRow + 1)

)

{

    writeoutput("<span class='staffoncal'>" & fnames[intRow] & " " & lnames[intRow] & "<br /></span>");

}

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
Participant ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

the problem is I can't really display the loop results right here:

{

    writeoutput("<span class='staffoncal'>" & fnames[intRow] & " " & lnames[intRow] & "<br /></span>");

}

I need to store those looped results in a variable and concatenate it to another variable later in the page. Here particularly, next to or with the allstaff var:

var allstaff = "<span class='staffoncal'>" & ValueList(getstaff.fname, "<br />") & "</span>";

outString = outString & "height='#height#'>" & allstaff & "<p /></td> ";

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
Valorous Hero ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

If you want to save the results to a variable, simply concatenate the values inside your for loop instead.  But there is no need to create extra arrays. Just access the query columns with array notation:

yourVar = "";

for (intRow = 1 ;intRow <= getstaff.RecordCount ;intRow = intRow + 1)

{

    yourVar = yourVar & getStaff.fnames[intRow] & " " & getStaff.lnames[intRow] & "....");

}

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 ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

lovewebdev wrote:

the problem is I can't really display the loop results right here:

{

    writeoutput("<span class='staffoncal'>" & fnames[intRow] & " " & lnames[intRow] & "<br /></span>");

}

I need to store those looped results in a variable and concatenate it to another variable later in the page. Here particularly, next to or with the allstaff var:

var allstaff = "<span class='staffoncal'>" & ValueList(getstaff.fname, "<br />") & "</span>";

outString = outString & "height='#height#'>" & allstaff & "<p /></td> ";

There you are. That's what I mean when I say that doing it this way allows you some freedom.

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 ,
Dec 05, 2011 Dec 05, 2011

Copy link to clipboard

Copied

Add the concatonated fields to your query.

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
Participant ,
Dec 06, 2011 Dec 06, 2011

Copy link to clipboard

Copied

Awesome. I think I got it now.

I was having problems because I used getStaff.fname as opposed getStaff.fname[intRow] when concatenated...

[intRow] was correct so what's the difference? I'm kind of new to cfscript and it looks funky. I'm so used to tags...

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
Valorous Hero ,
Dec 07, 2011 Dec 07, 2011

Copy link to clipboard

Copied

LATEST

getStaff.fname[intRow] retrieves the value from a specific row in the query. Unless you are within a query loop, getStaff.fname retrieves the value in the first row of the query.

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