| ||||||||||||
Update syntax Posted by bschultz (bschultz), 11 February 2004 I'm working on an "edit" or "update" script. I've got it working, but now want to "simplify" the script.The update syntax I'm using is this: Code:
This works just fine. I wrote a loop (since I have over 100 field names to update) to step through the fields. That loop goes like this: Code:
That also works just fine. The problem that I'm running into is how to get the loop into the UPDATE. I've read up on the mysql site, and can't find any tutorials to include the loop into the update sqlquery. I've tried to make the loop as a variable: "$loop = "loop script here" and then just call the variable, but I have so many quotes in there, I can't seem to get it to work. Can someone give me a push in the right direction, or a link to what the correct way to do this is? Thanks. Brian Posted by admin (Graham Ellis), 11 February 2004 Rather than print the query, build it up in a string with a .= operator .... thusCode:
Note the care I've taken to avoid a trailing comma! I've also assumed your incoming values are in an array. Try it first by printing out the query ... Posted by bschultz (bschultz), 11 February 2004 2 things...1-where did the $tab come from? 2- this isn't in an array, but I can certainly put it in one. I'll work on it some tonight. Better get back to the "real" job now. Thanks. Brian Posted by admin (Graham Ellis), 11 February 2004 You put your data into $tab before you get to this code - it's just a place that my loop gets its data from. Posted by bschultz (bschultz), 11 February 2004 makes sense...just wanted to make sure that wasn't some function I'm not aware of.Posted by bschultz (bschultz), 12 February 2004 This is where I am now...Code:
And then I printed the query...here's what it said: Quote:
You'll notice that the values are very random...some commas, some integers...when it should print out the variable name. Where are those values coming from? Posted by admin (Graham Ellis), 12 February 2004 They're coming from $tab.You have set up $tab as a string containing 1, 2, 3, 4 etc and not a a normal array. You're then stepping through that string character by character, putiing each character in turn into your query. I don't think it's what you intended Try instead $tab = range (1,141); for testing This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| |||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |