Ok, I have a table for users. I want to change the field "user_level" in the table to have the value 0. Because of the port many users are at many different levels which determine admin/mod status, so I want to revert everyone to 0 which is standard user.
I know its probably simple, using UPDATE <table> blah blah.. but, I'm MySQL challenged
Ok, lets try ONE more thing. Everything is great except one field in the users table. With the old system the user_regdate was stored as a varchar(11) value, so the date was like "Nov. 10, 2001" or whatever. Well the new software stores the regdate as an int(8) and each date is stored as a string of number that make no sense. I can't see how they get a date from the number.
So, there are two things I'm considering. One, how could I convert all the varchar values into the new int values?
Second, how can I just insert the user_regdate field from the old table into the new one. Because after the port it reverted all the dates to 0, so all 2700 members have all registered the same day So if anything I'd like to just fill that field with the existing data, and work on getting it to display from there.
EDIT - I stumbled across this, for the import script doing the reverse of what I want:
code:FROM_UNIXTIME(user_regdate,'%b %d, %Y') as user_regdate
So, since it used to be a string of numbers (ie. 10291023) I'm assuming unixtime can format dates into other formats, like what was shown, to make it Month. Day, Year as it is now. I think the string of numbers is the "seconds since 1/1/70" or something? I dunno
But if anyone is familiar with unixtime and how to convert back to other formats I'd love to hear it
Thanks Dave, I have been at that site all morning trying various commands with no luck. I was also talking to a friend of mine who does a lot of mysql/php work for his company, and he had some good ideas as well but nothing worked.
It would be fairly simple if the "'Month Day, year" data was stored in DATETIME format and not VARCHAR When we try to run the conversion it will format it, but gives all 0's. Stupid coders not doing things right
Anyway, since it seems impossible via a direct MySQL query, the only option is to create a script. So, my reasoning for a script is this.
Pull the current date format info out of the table as text. So it would just pull say "Jun 10, 2002". Pull these according to the 'username' field.
Then convert the text via the script to unix time.
Insert the new value into the appropriate username's datereg field.
The only problem would be finding the conversion code. I have seen websites that allow you to enter dates and have it convert for you that way, so I'm sure its out there, just a matter of finding it.
Let me know if that makes sense or I'm completely lost and this won't work at all (which is a possibility, lol)
Wow, that's awesome Dave! Seems like both Dave's on this site are amazing I will play with it and see if I can make an automated script to update all the entries. If it works, I owe you one big time!
// Open database connection // $link = mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect"); mysql_select_db($dbname) or die("Could not select database");
$query = "select username,user_regdate from usersnuke"; $result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) { $curruser = $row["username"]; $timestamp = date_str_to_unixtimestamp($row["user_regdate"], TRUE); $query2="update phpbb_users set user_regdate = '$timestamp' WHERE username = '$curruser'"; $update_result = mysql_query($query2); echo "Ran update query on user: $curruser with result: $update_result";
// Given date string 'MMM DD, YYYY', return unix timestamp. // // If date string is invalid: // If $debug is omitted or FALSE, return 0. // If $debug is present and TRUE, return 1 if syntax is bad, 2 if month name is bad, 3 if date is bad.
function date_str_to_unixtimestamp($date_string, $debug = FALSE) {
My mistake, I spelled one of the tables wrong. lol
BUT IT WORKED!!!!!!!!!!!!!!!!!!!!!! Wow, I'm still in shock, I had deemed this impossible late last night. Thanks Dave for your awesome help. If you need anything, maybe I can hook you up
Very nice, only two users failed the conversion, and they were users who had invalid usernames anyway, so POOF be gone
Now that I've learned so much about the phpbb system and its issues, hopefully I can make a conversion for threads, I feel I need to give something back
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.