Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2003, 10:49 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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]
Reply With Quote
  #2  
Old 05-12-2003, 10:52 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 05-12-2003, 10:58 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think I fully understand... Can you post an example?
Reply With Quote
  #4  
Old 05-13-2003, 04:47 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 05-13-2003, 09:44 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 05-13-2003, 10:12 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]
Reply With Quote
  #7  
Old 05-13-2003, 10:23 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Reply With Quote
  #8  
Old 05-13-2003, 11:49 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #9  
Old 05-14-2003, 11:34 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

doublequotes are wrong, you have to use ' in sqlqueries
Reply With Quote
  #10  
Old 05-14-2003, 03:38 PM
SiGmA_X SiGmA_X is offline
 
Join Date: Sep 2002
Location: Portland, OR, USA
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, I'll change that. But it works with doublequotes in your example and in the short one that I wrote in post 394,761 a bit up the page
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:58 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04116 seconds
  • Memory Usage 2,250KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete