update incrament value if new value is set

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default update incrament value if new value is set

    what I would like to do is if a user submits a new article and they set the
    order of the article to 1 then I would like a script to go through the table
    and increment the current items so that there would not be to items with the
    same order. but I would also like it to stop if there is a gap in the order.

    example:
    in the database there is
    Item name Order Number
    second 1
    third 2
    fourth 3
    fifth 5

    the user adds a new item with the order of one, the new list will appear like
    this:
    Item name Order Number
    first 1
    second 2
    third 3
    fourth 4
    fifth 5

    any suggestions?

    right now I have it like this but it incumbents all item and does not stop if
    there is a gap in the number, and will also increase all items even I set the
    order to an unused item.





    <cfquery name="get_current_order" datasource="#ds#">
    SELECT qID, qOrder FROM question WHERE qOrder => #qOrder# AND qSurvey =
    #qSurvey# ORDER BY qOrder
    </cfquery>
    <cfloop query="get_current_order">
    <cfquery name="get_next_order" dbtype="query">
    SELECT qID FROM get_current_order WHERE qOrder = evaluate(#qOrder#+1)
    </cfquery>
    <cfif get_next_order.recordcount gt 0>
    <cfquery name="change_order" datasource="#ds#">
    UPDATE question SET qOrder = (evaluate((SELECT qORder FROM question
    WHERE qID = #qID#) + 1)) WHERE qID = #qID#
    </cfquery>
    </cfif>
    </cfloop>

    bawaite Guest

  2. Similar Questions and Discussions

    1. why is the "Adobe Acrobat 6.0.1 Update" message there at the top? -- the update doesn't work
      why is the "Adobe Acrobat 6.0.1 Update" message there there at the top? -- the update doesn't work
    2. 6.0.1 update...
      Does anyone know whats new in this update or could direct me to a link where I may learn what new in this update? Thanks in advance
    3. 5.0.7 Update Pack 1 requires SCO Update license?
      I was just up on SCO's FTP site and noticed they have, as of today, Update Pack 1 and Maintenance Pack 1. I have a question about the Update Pack...
    4. cannot update...
      Have you tried response.write on the resulting query..just to see if it is picking up all your information correctly. Check your variables. are...
    5. Specifying "do not update" values in "additive" UPDATE sprocs
      Hello, I want to write a sproc whose purpose is to perform 'additive' UPDATEs to a given table. By 'additive', I mean I would like the existing...
  3. #2

    Default Re: update incrament value if new value is set

    You could declare a variable outside the loop and store the id of the last item
    changed there, and compare it to the next item in the loop. If currentID >
    lastID + 1 then stop the loop. This only works if they are in order and you
    only have one gap.


    blinkingCursor 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