vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   mass update of users Help... (https://vborg.vbsupport.ru/showthread.php?t=51180)

lemarsu 04-04-2003 01:18 PM

mass update of users Help...
 
I need to do a mass update of users based on some field in different tables

I have written some SQL but it would not work under mysql (in the office DB2 and oracle are ok with this kind of sql)

This is what I am trying to run :
Code:

UPDATE user,userfield
        SET user.usergroupid=8
        WHERE
                userfield.userid=user.userid AND
                userfield.field8= 'United Kingdom' AND
                user.usergroupid='5'

Can anyone please help....

Thanks
LeMarsu

Xenon 04-04-2003 01:27 PM

hmm i don't know the update command very well, but maybe this will work:

[sql]UPDATE user LEFT JOIN userfield USING(userid) SET usergroupid=8 WHERE field8='United Kingodm' AND usergroupid=5[/sql]

lemarsu 04-04-2003 02:41 PM

that doesn't work as well !!

There is something in myphp I don't get ! I can only do simple update Queries !

I don't know where I read this but apparently you can do updates with joins in mySQL ... can that be true !!?

LeMarsu ... need HELP !!!

mr e 04-04-2003 03:11 PM

when it doesn't work, what happens? if you just copied xenons query exactly it had a spelling error at Kindom

lemarsu 04-04-2003 04:17 PM

this is the error I get :

Quote:

Error
SQL-query :

UPDATE
user
LEFT JOIN
userfield
USING(userid)
SET usergroupid=8
WHERE field8='United Kingdom' AND usergroupid=5


MySQL said:


You have an error in your SQL syntax near 'LEFT JOIN
userfield
USING(userid)
SET usergroupid=8
WHERE field8='United ' at line 3

lemarsu 04-06-2003 08:32 AM

I found this posts on the web...
http://www.geocrawler.com/archives/3...9/3/0/1441850/


Quote:

You can`t do a join in an update (or delete) statement. So you
have to select the rows you want to update in one query, then
join the selected IDs into a string separated by commas, then
update WHERE iparty_sku IN (<string of selected IDs>).

Xenon 04-06-2003 09:49 AM

that means you have to write a script which selects u the rows to update at first:

PHP Code:

<?php
require('./global.php');
$users=$DB_site->query("SELECT user.userid FROM user LEFT JOIN userfield USING (userid) WHERE user.usergroupid=5 AND userfield.field8='United Kingdom'");
$userids '(0';
while(
$user=$DB_site->fetch_array($users)) {
$userids .= ','.$user['userid'];
}
$userids .= ')';
$DB_site->query('UPDATE user SET usergroupid=8 WHERE userid IN '.$userids);

?>



All times are GMT. The time now is 11:42 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.01785 seconds
  • Memory Usage 1,728KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete