Previous Thread
Next Thread
Print Thread
Hop To
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
I'm trying to find out how many 'active' users I have.

Would anyone know an SQL query for the number of posters in the last (say) 60 days?

Thanks smile

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
Code
SELECT Count( * ) AS UserPosts, POST_POSTER_NAME
FROM ubbt_POSTS
WHERE POST_POSTED_TIME > UNIX_TIMESTAMP( '2008-04-20 00:00:00' ) -86400 *60
GROUP BY POST_POSTER_NAME
ORDER BY UserPosts DESC

change 2008-4-20 to whatever date you would want the 60 days to be counted back from..

*note* this is off top of my head.. i did try it to see if it passed mysql parser at least.. laugh

ps: this is a little diff than waht you asked for -- if you just want it simple (like you posted), i'll give that a whirl

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
simplified version -- will count the number of unique posters (assumes you have mysql 5)

Code
SELECT count(posters.POST_POSTER_NAME) from (SELECT Count(up.POST_ID) AS UserPosts, up.POST_POSTER_NAME
FROM ubbt_POSTS up
WHERE up.POST_POSTED_TIME > UNIX_TIMESTAMP( '2008-04-20 00:00:00' ) -86400 *60
GROUP BY up.POST_POSTER_NAME) posters

many other ways to 'skin a cat', but this works too wink

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Oh these are very good smile
Thanks Sd!

Joined: Jun 2006
Posts: 3,837
I
Ian Offline
Carpal Tunnel
Carpal Tunnel
I Offline
Joined: Jun 2006
Posts: 3,837
Thanks SD smile

1037 - could be worse smile

Now can you or anyone help on converting the top posters in the last 30 days? wink I have tried but failed frown

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Converting them to what?

Surely this is a secular forum wink ?

Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
Code
SELECT Count( * ) AS UserPosts, POST_POSTER_NAME
FROM ubbt_POSTS
WHERE POST_POSTED_TIME > UNIX_TIMESTAMP( '2008-04-20 00:00:00' ) -86400 *30
GROUP BY POST_POSTER_NAME
ORDER BY UserPosts DESC
LIMIT 10

(Modifying SD's code) gives you the top 10 posters from the last 30 days smile


- Allen
- ThreadsDev | PraiseCafe
Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
I guess that's actually the top 10 from the previous 30 days prior to April 20th. crazy

Adjustment to use current time (whatever time that is?)?


- Allen
- ThreadsDev | PraiseCafe
Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
Code
SELECT Count( * ) AS UserPosts, POST_POSTER_NAME
FROM ubbt_POSTS
WHERE POST_POSTED_TIME > UNIX_TIMESTAMP( CURRENT_DATE ) -86400 *30
GROUP BY POST_POSTER_NAME
ORDER BY UserPosts DESC
LIMIT 10

Seems to work fine, MySQL 5+


- Allen
- ThreadsDev | PraiseCafe
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
^^ Allen figured it out.. sorry for my not explaining the variables smile

ah and CURRENT_DATE is nice to know!!

ty Allen! smile

Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
You're welcome, though my little piece was a matter of googling dev.mysql.com smile I've been wanting to write a mod like this forever for a custom island - I'd still need to figure out the

$a = something
$b = somethingelse

echo "$a $b"

part for the CI smile


- Allen
- ThreadsDev | PraiseCafe
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
lemme know specifically what you want (via PM if you want) and i can whip that up for you for zero Cents laugh

i've done quite a few already like that (i think) and it should be like rolling off a log now..

Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
It's just a mod/custom island that shows "Top 10 Posters" for the last 30 days. I know there's been lots of requests for it.

Would this be close?

Code
/* PHP CODE HERE */
$top10 = $db->query ("
SELECT Count( * ) AS UserPosts, POST_POSTER_NAME
FROM ubbt_POSTS
WHERE POST_POSTED_TIME > UNIX_TIMESTAMP( CURRENT_DATE ) -86400 *30
GROUP BY POST_POSTER_NAME
ORDER BY UserPosts DESC
LIMIT 10
");
/* BODY HERE */
$body = <<<EOF
$top10
EOF;


- Allen
- ThreadsDev | PraiseCafe
Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
And would it "thump" a server if used as a custom island and queried with every page load?


- Allen
- ThreadsDev | PraiseCafe
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
eek well, you are semi-close -- but um.. not there.. lemme gin one up for you and paste here..

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
the idea is more like this, btw

Linky Poo

that idea needs to be modified for your case with the above query involved instead.. then build the HTML and pump it out to the body smile

i'll clean up a better example for you though

btw: i did a custom island (sorry didn't remember before) that lists Top: All time | Month | Week | Today (in the right/lefttdheader)

then the users just click on each as a 'link' and the javascript swaps in the appropriate hidden div.. so you essentially get 4 islands in one.. and the code allows the coder (you) to decide which one is displayed as a default on page initial load..

i can post that over @ ubbdev

Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
That would be cool, grazie smile


- Allen
- ThreadsDev | PraiseCafe
Joined: Jul 2006
Posts: 4,057
Joined: Jul 2006
Posts: 4,057
yeh post and linky poo

SD brings it to the table once again wink
The option one sound cool smile


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Originally Posted by Mark S
The option one sound cool smile
The option one sound cool 4 me 2 laugh

Joined: Jul 2006
Posts: 4,057
Joined: Jul 2006
Posts: 4,057
Do they take Blue Peter Badges in 37.0622,-95.677061 ?


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
i need to 7.3-ize it, then i'll pop over @ ubbdev

/me googles 'Blue Peter Badge' -- sounds kinky eek

Joined: Jun 2006
Posts: 3,837
I
Ian Offline
Carpal Tunnel
Carpal Tunnel
I Offline
Joined: Jun 2006
Posts: 3,837
Not half as much as Valerie Singleton wink

Although I preferred John Noakes & Peter Purves

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Val - well known lezza wink
If only I had any ideas where her fingers had been before she started making stuff with sticky backed plastic.... wink

Quote
Although I preferred John Noakes & Peter Purves
Not too much, I hope wink

Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
Likes: 116
I'm not even going to ask...


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
No wonder we're all so warped after watching all that kids TV crazy

Joined: Jun 2006
Posts: 3,837
I
Ian Offline
Carpal Tunnel
Carpal Tunnel
I Offline
Joined: Jun 2006
Posts: 3,837
can you even buy sticky backed plastic now?

Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796


- Allen
- ThreadsDev | PraiseCafe
Joined: Jun 2006
Posts: 3,837
I
Ian Offline
Carpal Tunnel
Carpal Tunnel
I Offline
Joined: Jun 2006
Posts: 3,837
That is sticky tape or sellotape - not sticky backed plastic wink

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
--- what was this thread about again ? --- :shrug:

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
I was sorted by post #3 laugh

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
After running this...
SQL Query
SELECT Count( * ) AS UserPosts, POST_POSTER_NAME 
FROM ubbt_POSTS 
WHERE POST_POSTED_TIME > UNIX_TIMESTAMP( CURRENT_DATE ) -86400 *60 
GROUP BY POST_POSTER_NAME 
ORDER BY UserPosts DESC 
I notice in one case...

UserPosts=2 POST_POSTER_NAME =

i.e. blank / empty.

Any thoughts on why this could be?

(I've deleted one user but he had many more posts than that.)

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Hey Rick, I like the SQL tags smile (First time I've seen them.)

Joined: Jul 2006
Posts: 4,057
Joined: Jul 2006
Posts: 4,057
We should have some default tools in there wink
Or saved query's.

I just keep saying SD is our hero and he delivers wink
Every time. (Dont you lol)


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Originally Posted by Mark S
We should have some default tools in there wink
Or saved query's.

I just keep saying SD is our hero and he delivers wink
Every time. (Dont you lol)


Agreed on both points..

Mah herooooh - swoons wink

I think it would be good to save the queries with a 'descriptive' name.

Also an 'are you sure' message before you delete (doh blush )

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
i added a description field to saved queries in the admin cpanel for 7.3 -- if that's what you were alluding to..

and quit swooning on me!! laugh

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
ok clever guy - well I haven't got 7.3 yet - but soon cool
...and hopefully gold as well smirk

As for swooning, you know you love it; so stop pretending laugh

Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
Likes: 116
And they say I'm good at derailing topics... seems driv is better at getting them back on track wink...


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Can't have that, can we?

Sorry mate it was an accident. Won't happen again wink


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
spam issues
by ECNet - 03/19/2024 11:45 PM
Who's Online Now
0 members (), 919 guests, and 149 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)