#yourQuery["someColumn"][currentRow]# [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> bottom line is if your going to do anymore very simple checks then you can use cfloop... with the query variables from it, but any deeper like nesting then define the arrays and use them.... with that said, if you can accomplish this with database queries then let it do it as it's more powerful than using cfml code... server memory etc etc.. rob [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => RobBurn [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 4 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Query+Array - Coldfusion Database Access

Query+Array - Coldfusion Database Access

Is there any way to store query resultS into an array so we could loop through it one by one....

Sponsored Links
  1. #1

    Default Query+Array

    Is there any way to store query resultS into an array so we could loop through it one by one.
    Sponsored Links
    incubusm Guest

  2. #2

    Default Re: Query+Array

    You can access query objects like an array. For example

    <!--- not tested --->
    <cfoutput query="yourQuery">
    #yourQuery["someColumn"][currentRow]#
    </cfoutput>
    mxstu Guest

  3. #3

    Default Re: Query+Array

    If you loop through the query, you don't have to worry about arrays.
    Dan Bracuk Guest

  4. #4

    Default Re: Query+Array

    Becareful using <cfoutput query="yourQuery"> I find it to be funky... lol. i do
    use it though.... I like the <cfloop query=queryname> to store variables and
    use them later as you cannot nest cfloop's or cfoutput - well it will let you
    nest cfloops but the answer will be incorrect as it will only give you the 1st
    variable in the top cfloop and not index through them. An example i think you
    are asking about would be as follows.


    <cfquery name="qTasks2" dbtype="query">
    SELECT DISTINCT cd, ea, PROJECT_NICKNAME,pm
    FROM qTasks
    ORDER BY cd,ea
    </cfquery>

    'arrays declared here

    <cfset acd=arraynew(1)>
    <cfset pm_name=arraynew(1)>
    <cfset aea=arraynew(1)>

    <cfif #qTasks.RecordCount# is 0>
    <h4>No EA with activities planned within request range</h4>
    <cfabort>
    </cfif>
    <cfset i = 0>
    <cfloop query="qTasks2">
    <cfset i = i+1 >
    'arrays defined here
    <cfoutput>
    <cfset acd=#cd#>
    <cfset aea=#ea#>
    <cfset pm_name=#pm#>
    </cfoutput>
    </cfloop>

    Then later I use it - within another query and yet that query is stored
    inside another set of arrays .. 2 diminsion in this case
    ..

    <cfloop index="i" from="1" to ="#qTasks2.recordcount#">
    <cfquery name="qWBS" dbtype="query">
    SELECT distinct cd, ea, startdate, enddate, wbslevel
    FROM qTasks
    WHERE cd='#acd#' AND ea='#aea#'
    </cfquery>
    <cfset j = 0>
    <!--- <cfdump var="#qWBS#"> --->
    <cfoutput query="qWBS">
    <cfset j = j+1 >
    <cfset awbslevel[j]=#wbslevel#>
    <cfset astartdate[j]=#startdate#>
    <cfset aenddate[j]=#enddate#>
    </cfoutput>
    <cfset taskwbscount=j>
    </cfloop>


    bottom line is if your going to do anymore very simple checks then you can use
    cfloop... with the query variables
    from it, but any deeper like nesting then define the arrays and use them....
    with that said, if you can accomplish this
    with database queries then let it do it as it's more powerful than using cfml
    code... server memory etc etc..

    rob

    RobBurn Guest

  5. #5

    Default Re: Query+Array

    >well it will let you nest cfloops but the answer will be incorrect as it will
    only give you
    >the 1st variable in the top cfloop and not index through them

    As you said, you can use nested loops, you just need to use a from/to loop
    instead of < cfloop query="..." >. However, since you can already access query
    values using array syntax:

    yourQuery[colName][rowNumber]

    ... a separate array is often unnecessary and can even be a waste of memory,
    if the goal can be accomplished using an existing query.

    You might want to respost your example using the "attach code" option. The
    code displayed in the html of your post may not be exactly as you posted it.
    The forums interpret [ i ] (with no spaces in between the brackets) as the
    symbol for italic text :-)

    On a side note, there are some unecessary pound "#" signs in the code. As per
    recommendations, pound signs should not be used here:

    <cfif #qTasks.RecordCount# is 0>
    <cfset awbslevel[j]=#wbslevel#>


    ... instead use ...


    <cfif qTasks.RecordCount is 0>
    <cfset awbslevel[j]= wbslevel >




    mxstu Guest

Similar Threads

  1. Question how can save query in array by used sql
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: April 29th, 09:53 AM
  2. I want to return an array instead of a query
    By swickes in forum Coldfusion Flash Integration
    Replies: 6
    Last Post: August 13th, 10:20 AM
  3. Sort array from a Query
    By bettina@coaster.ch in forum MySQL
    Replies: 3
    Last Post: November 29th, 10:06 PM
  4. Query Stored In array
    By akcreative in forum Coldfusion Database Access
    Replies: 1
    Last Post: August 23rd, 04:35 PM
  5. [newbie] Array and query
    By Nexus in forum PHP Development
    Replies: 4
    Last Post: September 16th, 08:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •