MyBB Community Forums

Full Version: I need a SQL Query.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

Please can anyone make me a SQL query for this?

if user has <50 posts and user has registered in 1330581600 (converted to unix timestamp) SET postnum to 55


I mean to update user who has less than 50 posts and registered after at this date 01/03/2012 to set up all with 55 postnum.

Because I have some section that requires min. of 50 posts to join.

It's urgent please!!

Thanks a lot guys!!
UPDATE mybb_users SET postnum = '55' WHERE postnum < 50 AND regdate = '1330581600';
(2012-04-04, 08:43 AM)Yaldaram Wrote: [ -> ]
UPDATE mybb_users SET postnum = '55' WHERE postnum < 50 AND regdate = '1330581600';

Hey Yaldaram, Thanks for the support!!! it's wrong as I see.

WHERE postnum < 50 AND regdate = '1330581600'

shouldn't be:?

WHERE postnum < 50 AND regdate < '1330581600'
According to your description it should actually be like this:

UPDATE `mybb_users` SET `postnum` = '55' WHERE `postnum` < 50 AND `regdate` > '1330581600';

You want the regdate value to be bigger than 1330581600, otherwise it will just target users who registered before that date. And you want to update users who registered after.
(2012-04-04, 09:47 AM)Fábio Maia Wrote: [ -> ]According to your description it should actually be like this:

UPDATE `mybb_users` SET `postnum` = '55' WHERE `postnum` < 50 AND `regdate` > '1330581600';

You want the regdate value to be bigger than 1330581600, otherwise it will just target users who registered before that date. And you want to update users who registered after.

Oh I'm really sorry. I made a mistake. It's before, not after.

Well I'm going to explain it better.

If the user has less than 50 posts and have been registered before of this day: 01/03/2012 SET postnum to 55

But I'm worried about this query, I don't want to set 55 posts to all my users that have +2000 posts and registered before the date I said.


Thanks.
Alright, in that case this would be it:

UPDATE `mybb_users` SET `postnum` = '55' WHERE `postnum` < 50 AND `regdate` < '1330581600';

The query is fine, you can run it safely. You can always make a database backup and if anything goes wrong you can just restore it. But like I said, the query is fine, you shouldn't have any problems.
Also note that if you run the Update User Post Counts tool, the value will change to what it really should be.