Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default CFLOOP

    The goal is to insert a record into table 'atd', which contains a document id
    and an associate id, for each document (38) and associate (150). So the end
    result should be 5700 records. The following code inserts a record for each
    associate and document but the document id doesn't change, it's always the
    first document id in the table. I end up with 5700 records but the document id
    is the same for all of them.

    What am doing wrong?

    <cfquery name="SelectDocuments" datasource="#application.dsn#">
    SELECT *
    FROM document
    WHERE associate_id = 1
    </cfquery>

    <cfquery name="GetAssociates" datasource="#application.dsn#">
    SELECT id
    FROM associate
    WHERE type = 'Associate'
    </cfquery>


    <cfloop query="SelectDocuments">
    <cfoutput query="GetAssociates">
    <cfquery name="AddDocumentRelationships" datasource="#application.dsn#">
    INSERT INTO atd
    (associate_id,
    document_id,
    display
    )
    VALUES
    (#GetAssociates.id#,
    #SelectDocuments.id#,
    'Y'
    )
    </cfquery>
    </cfoutput>
    </cfloop>

    drmaves Guest

  2. Similar Questions and Discussions

    1. cfloop error
      I am getting an error that is resolving to the closing tag for the </cfloop>. Any Ideas? <cfoutput query="Recordset1" group="category"> <table...
    2. Cfloop..
      I am trying to loop over a list: <cfquery name="updsyllabus" datasource="#arguments.syl.dsn#"> UPDATE #arguments.syl.tname# SET <cfloop...
    3. <cfloop> question
      The code below generates a list of form fields for my form. I've been asked to see if it's possible to skip a line after every two form fields. Is...
    4. to cfloop or not to cfloop?
      :confused; I have a list of checkboxes from a form, and a submit button for "Batch Print" The var is "SelectList" and comes out as comma dilimited....
    5. CFLOOP/CURRENTROW
      I have a LOOP that runs over a query and I use CURRENTROW so that I can then use MOD on it so I can utilize repeating ARRAY data to change the color...
  3. #2

    Default cfloop

    I have one query that gets all records where the login is not defined. I then
    want to reset the order for all the records to one, and then set new ordering
    for the records starting with 1 again. the problem I am encountering is that
    It is looping through all the records and setting the new order to 6 which is
    the total number of records. Can anyone help?
    <cfquery name="GetOrdering" datasource="BusOff" Username="BusOff"
    Password="asproi">
    SELECT Ordering
    FROM logins
    WHERE salesconsultant = '1'
    and loginID <> #LOGINID#
    order by Ordering
    </cfquery>

    <cfset Neworder = 1>
    <cfloop query="GetOrdering">
    <cfquery name="UpdateOrdering" datasource="BusOff" Username="BusOff"
    Password="asproi">
    UPDATE logins
    SET Ordering = #Neworder#
    where loginID <> #LOGINID#
    </cfquery>
    <cfset Neworder = Neworder + 1>
    </cfloop>

    akola Guest

  4. #3

    Default Re: cfloop

    it appears youre updating every record on each increment, which would explain why they all equal the same.
    gwgiswebmaster Guest

  5. #4

    Default cfloop

    I have to compare the ?name? from tb1 and ?name? from tb2?.
    The ?tb1? table has the following fields (dn, uid, c_name, c_time, m_time )
    The ?tb2? table has the following fields: (Name, Ref, Act).
    Process: If record found in tb1, the Directory field value for that record
    shall be YES, else NO. I have my code up and run but it takes forever to
    generate the report. Attached is my code, please fell free to modify or any
    advice would be much appreciated


    <cfquery name="gettbl" datasource="#db#" timeout="600">
    select *
    from tb1
    </cfquery>
    <cfoutput>
    <table width="735" cellpadding="0" cellspacing="0" border="1">
    <tr>
    <th>Directory</th>
    <th>UID</th>
    <th>Name</th>
    <th>Reference Number</th>
    <th>Activation Code</th>
    <th>C Name</th>
    <th>C Time</th>
    <th>M Time</th>
    </tr>
    <cfloop query="gettbl1">
    <cfset UID ="#uid#">
    <cfset name ="#name#">
    <cfset cn ="#c_name#">
    <cfset ct ="#c_time#">
    <cfset mt ="#m_time#">

    <cfquery name="getname" datasource="#db#" timeout="600">
    SELECT Name, Ref,Act
    FROM tb2
    </cfquery>

    <cfloop query="getname">
    <cfset e_name = "#name#">
    <cfset Ref ="#Reference#">
    <cfset Act ="#Activation#">

    <cfif name_string EQ dn>
    <tr>
    <td>Y</td>
    <td>#UID#</td>
    <td>#Ref#</td>
    <td>#Act#</td>
    <td>#name#</td>
    <td>#cn#</td>
    <td>#ct#</td>
    <td>#mt#</td>
    </tr>
    <cfelse>

    <tr>
    <td>N</td>
    <td>#UID#</td>
    <td>#Ref#</td>
    <td>#Act#</td>
    <td>#name#</td>
    <td>#cn#</td>
    <td>#ct#</td>
    <td>#mt#</td>
    </tr>
    </cfif>

    </cfloop>
    </cfloop>
    </cfoutput>

    kt03 Guest

  6. #5

    Default Re: cfloop

    One thing that might help is to move your getname query outside the loop. See
    below.



    <cfquery name="getname" datasource="#db#" timeout="600">
    SELECT Name, Ref,Act FROM tb2
    </cfquery>

    <cfloop query="gettbl1">
    <cfset UID ="#uid#">
    <cfset name ="#name#">
    <cfset cn ="#c_name#">
    <cfset ct ="#c_time#">
    <cfset mt ="#m_time#">

    jdeline Guest

  7. #6

    Default Re: cfloop

    Tried that but it din't help, any other sugesstions? tb1 has about 55xx records, tb2 has about 26xx records. I don't think because amount of data but may be my code isn't right.

    Thanks
    kt03 Guest

  8. #7

    Default Re: cfloop

    If tb 1 has 55xx records, that means the <cfloop query="gettbl1"> loops 55xx
    times and your <cfquery name="getname" datasource="#db#" timeout="600">
    executes 55xx times. I can't believe moving it outside the loop didn't make any
    difference.



    jdeline Guest

  9. #8

    Default Re: cfloop

    I don't know either but I did try your sugesstion and it didn't make any diffrent. Would be other another part of my code cause the problem?
    kt03 Guest

  10. #9

    Default Re: cfloop

    use subqueries.
    ayhanyildiz Guest

  11. #10

    Default Re: cfloop

    kt03,

    If you mean your tables contain 5500 and 2600 records, then I think the total
    number of loops in the code is over 14 million times ... literally. If this is
    the case, it is not suprising the code takes a long time ... what it IS
    suprising is that it works at all ;-)


    I have to compare the ?name? from tb1 and ?name? from tb2?.
    The ?tb1? table has the following fields (dn, uid, c_name, c_time, m_time )
    The ?tb2? table has the following fields: (Name, Ref, Act).
    Process: If record found in tb1, the Directory field value for that record
    shall be YES, else NO.

    If the data in the two tables is related by a common column then you need to
    use a SQL JOIN to retrieve the correct information. Right now all the code
    does is basically output a
    [url]http://www.google.com/search?hl=en&q=define%3Acartesian+product&btnG=Goo gle+Sear[/url]
    ch, which is almost certainly NOT what you want.

    What is the relationship between the two tables? Are you trying to retrieve
    records where the tb1.Name = tb2.Name? If you can you provide more information
    .... or better yet .... an example of the values you want to output, someone can
    help you design a better query.




    mxstu Guest

  12. #11

    Default cfloop

    Hello,

    I am trying to allow a user to search for records, based on their criteria,
    which will load a form. This form will show how many records sets fit the
    criteria, which record (3 of 40) they are on and 30+ fields of information
    based on the id of the record set.

    I have a cached query which retieves a list of record id's based on a
    information posted from a form. I cannot, for the life of me, figure out how
    to navigate through the id's, how do I load the form with the "next" record or
    "prior" record?



    Thanks in advance,

    Matt

    <cfif action IS "sortrecs">
    <cfset lengthquery="">
    <cfset looppos="">
    <!--create list--->
    <cfquery datasource="#ds#" name="idlist"
    cachedwithin="#CreateTimeSpan(0,0,30,0)#">
    SELECT dbo.tblClientInformation.clientID
    FROM dbo.tblClientInformation
    WHERE tblClientInformation.ClientCaseTypeID=#form.casety pe#
    </cfquery>
    <!--get the length of the list--->
    <cfoutput query="idlist">
    <cfset recordsetnum=#idlist.recordcount#>
    </cfoutput>
    <!--put comma in for deliminator--->
    <cfset beglist=ValueList(idlist.ClientID)>
    <cfset looppos=#ListGetAt(beglist,1, ",")#>
    <cfloop from="1" to="#lengthquery#" index="looppos">
    <cfquery datasource="#ds#" name="sortedData">
    SELECT dbo.tblClientInformation.*, dbo.tblCaseType.CaseType
    FROM dbo.tblClientInformation INNER JOIN dbo.tblCaseType ON
    dbo.tblClientInformation.ClientCaseTypeID = dbo.tblCaseType.CaseTypeID
    </cfquery>
    </cfloop>

    </cfif>

    shastamatt Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139