advanced varables syntax?? help would be good

Discussion in 'Programming' started by rcollins, Oct 8, 2008.

  1. #1
    <cfloop index="x" from="1" to="300">
    <cfif isdefined("form.update#x#") or isdefined("form.delete#x#")>
    <cfset form.updatenum = "#x#">


    <cflock timeout="5" throwontimeout="No" name="#session.sessionID#" type="EXCLUSIVE">
    <cfquery name="change" datasource="olivers" dbtype="ODBC">

    UPDATE menu
    SET menuitem='#form.item##updatenum#', addinfo='#form.info##updatenum#', price='#form.price##updatenum#'
    WHERE ID = '#form.updatenum#'
    </cfquery>
    </cflock>

    </cfif>
    </cfloop>


    my problem is that i need to make something like this '#(#form.item#)(#updatenum#)#' to go into query but i dont know the proper syntax.



    this is where it is calling from


    <cfoutput Query="getdata2"><p class="standardtxt">
    Item Title: <cfinput type="text" name="item#ID#" visible="true" value="#menuitem#" maxlength="300" width="300" size="50"><br>
    Extra info: <cfinput type="text" name="info#ID#" visible="true" value="#addinfo#" maxlength="300" width="300" size="40"><br>
    Item Cost: <cfinput type="text" name="price#ID#" visible="true" value="#price#" maxlength="300" width="300" size="5"><br>
    <strong>
    <cfinput name="update#ID#" type="submit" value="Update" />
    </strong>
    <cfinput name="delete#ID#" type="submit" value="Delete" />

    <br></p><br> <cfinput type="hidden" name="ID" value="#ID#">
    </cfoutput>

    and it dispalys alot and i need to be able to update them

    now this not the only way i have tried it i think i am missing a small easy step that i dont now how to do so any help would to great :)
    thanks in advance or for just for having a look.:)
     
    rcollins, Oct 8, 2008 IP
  2. CR250

    CR250 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use evaluate(dynamicVariable) ie:

    <cfset form = structNew() />
    <cfset form.item1 = "one" />
    <cfset form.item2 = "two" />
    <cfset form.item3 = "three" />
    <cfset form.item4 = "four" />
    <cfset form.item5 = "five" />
    <cfloop index="x" from="1" to="5">
    <cfset item2="form.item#x#">
    <cfoutput>#evaluate(item2)#<br /></cfoutput>
    </cfloop>
     
    CR250, Oct 8, 2008 IP
  3. rcollins

    rcollins Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sorry you must have misunderstood me but thanks for the reply.
    i have tried to explain myself a little better too.
     
    rcollins, Oct 8, 2008 IP
  4. CR250

    CR250 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yep like I said evaluate:

    <cfset instertData = "form.item#updatenum#" />
    <cfset instertinfo = "form.info#updatenum#" />
    thing use this to insert:

    UPDATE menu
    SET menuitem='#evaluate(instertinfo)#',
    addinfo='#evaluate(instertData)#',
    ice='#form.price##updatenum#'
    WHERE ID = '#form.updatenum#'

    Also you should use cfqueryparam
     
    CR250, Oct 8, 2008 IP
  5. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can, but you should avoid using evaluate unless it is really necessary. In most cases it is not.

    Use associative array notation. Not tested, but here is the idea:

    UPDATE menu
    SET menuitem = '#form["item"& updatenum]#'
    ....

    You should also use cfqueryparam on all query parameters.
     
    cfStarlight, Oct 9, 2008 IP
  6. rcollins

    rcollins Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks :) i got it woking i ended up having a simple error thanks for the help
    this is what worked best
    UPDATE menu
    SET menuitem='#form["item"& updatenum]#', addinfo='#form["info"& updatenum]#', price='#form["price"& updatenum]#'
    WHERE ID = #form.updatenum#
    im very greatfull for the help:)
     
    rcollins, Oct 9, 2008 IP