The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Mass Update (MySQL & PHP)
Okay, I just typed this out in a long message, but IE crashed, so you are getting the short version now!
I need to update 21 records in one batch, that updates the same field and same table. Right now, it is doing 21 loops and 21 queries, and that is slow. Here is the current query, if you can help at all, please do!![sql]UPDATE pchm_affiliates SET impressions=$impressions WHERE id=$id[/sql] |
#2
|
|||
|
|||
I had this problem a while ago and the only solution I could get was a cheap hack: a huge succession of nested IFs in the SET clause.
|
#3
|
|||
|
|||
I don't think I fully understand... Can you post an example?
|
#4
|
||||
|
||||
you have to post a bit more about the structure itself.
should everyfield be updated with different infos, or with the same... also filburt is right, a long nested if clause helped him in a similar problem, search around MyChenQL questions |
#5
|
|||
|
|||
Well, it needs to update all the records based on id, but only one field (impressions) needs updating. The data will be diffrent for each, most likely.
I'll search for the keyword 'MyChenQL' but what is it? |
#6
|
|||
|
|||
Okay, I looked at this thread and tried out a IF in a query... Here's the query I tried it with:[sql]UPDATE pchm_affiliates SET impressions = IF(id=10,"840",IF(id=11,"732")) WHERE id IN (10,11)[/sql]Guess what? It worked! Now I just have to modify my script to handle it
Thanks Xenon, thank you a lot! One more thing tho, how about a multi-table COUNT()? I can do it if I used COUNT(*) but not if I used COUNT(id) or something like that. I need to count it on a single column, and then I can make it work with out a loop. So, how do I make this work?[sql]SELECT COUNT(id) WHERE id=1[/sql] |
#7
|
|||
|
|||
Humm, having a little trouble with a loop for this because of the looping parans in the IF. The amount of affiliates could change, so it has to loops and cannot be set. How can I close the ')'s each time, because pf the IF...
|
#8
|
|||
|
|||
Humm, okay.. I have been working on this, and got my loop to work, or so it seems. It returns a error when ran in phpMyAdmin however. Here is the MySQL Query[sql]UPDATE pchm_affiliates SET impressions = IF (id=8, "908",
IF (id=3, "1993", IF (id=4, "927", IF (id=7, "872", IF (id=5, "1728", IF (id=10, "873", IF (id=1, "1907", IF (id=6, "1894", IF (id=2, "1904", IF (id=9, "871", IF (id=11, "765"))))))))))) WHERE id IN (8,3,4,7,5,10,1,6,2,9,11)[/sql]If anyone can help.. Thanks! |
#9
|
||||
|
||||
doublequotes are wrong, you have to use ' in sqlqueries
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|