View Full Version : Quick SQL question
DarkSavior
01-29-2004, 08:58 PM
Any way to quickly reset an user's info with one SQL command? Like that it restores everything to their default setting.
I need to reset items_user table for specific userid with 1 command to it's default values but don't know how. :(
Would be something like...
UPDATE items_user SET (what do i put here?) WHERE userid=$bbuserinfo[userid]
DarkSavior
02-01-2004, 05:39 PM
No idea how to reset a row to default values except the user id? :/
Boofo
02-01-2004, 05:45 PM
Couldn't you just use DEFAULT?
g-force2k2
02-01-2004, 05:48 PM
I could write you the sql statement, but I know the itemshop works similar to profilefields so in order to reset all of them I would need to know exactly what your sql structure for that table is. If you do a backup for the items_user table to get its structure I will gladly write you the sql.
Cheers,
g-force2k2
DarkSavior
02-01-2004, 06:59 PM
Ok here it is for the current data.
g-force2k2
02-01-2004, 07:08 PM
DarkSavior try this code:
$items = $DB_site->query_first ( "SELECT * FROM items_user WHERE userid=$bbuserinfo['userid']" ) ;
for ( $x = 0; $x <= 50; $x++ ) :
$item = "item" . $x ;
$points = "points" . $x ;
$desc = "description" . $x ;
if ( $items["$item"] ) :
$update[] = "$item = 'No Item'" ;
endif ;
if ( $items["$points"] ) :
$update[] = "$points = '0'" ;
endif ;
if ( $items["$desc"] ) :
$update[] = "$desc = 'No Description Available'" ;
endif ;
endfor ;
if ( sizeof ( $update ) > 0 ) :
$DB_site->query ( "UPDATE items_user SET " . implode ( ", ", $update ) . " WHERE userid=$bbuserinfo[userid]" ) ;
endif ;
DarkSavior
02-01-2004, 07:22 PM
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\www\forums\member.php on line 1245
Getting that one... Line 1245 is the first line of that code. I just added it after the partial reset add-on.
g-force2k2
02-01-2004, 07:30 PM
Try making $bbuserinfo['userid'] just $bbuserinfo[userid]
Regards,
g-force2k2
DarkSavior
02-01-2004, 07:33 PM
Ok that one worked. Thanks, gotta add it to reset the Icon too though, but I think I can manage it with this now. :)
Thanks again g-force2k2!
g-force2k2
02-01-2004, 07:35 PM
Ok that one worked. Thanks, gotta add it to reset the Icon too though, but I think I can manage it with this now. :)
Thanks again g-force2k2!
Hey no problem, just make sure after it is reset that it actually reset. Do another download of the sql structure and make sure all the values went back to their defaults. I want to know if the query worked, thanks.
Cheers,
g-force2k2
DarkSavior
02-01-2004, 07:40 PM
Yep it definitely did, my items and stats were reset to default values, only the icon doesn't want to reset, even after adding IF code to reset it back to ''.
Checked through phpmyadmin and all items surely disappeared from there. :)
EDIT: Ok got it now, now it's a full-fledged user reset for rpg.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.