Discussion Board
Welcome Guest! You can login or register. Login or Register.

Options
Go to last post Go to first unread
Zero2Cool  
#1 Posted : Thursday, January 6, 2011 3:30:33 AM(UTC)
I'd like a SQL statement that finds the amount of posts for each user, then updates the specific field with that number.



On table_fpro_posts I want the count of posts that equal the poster_id and then update the field field_user_posts on table_users.

The relation between the tables would be user_id from the table_users table and poster_id from the table_fpro_posts table.


Code:
table_users		table_fpro_posts
user_id		=	poster_id



I've noticed several members with a post count that is not accurate and I'd like to fix that, but not sure where to start with the SQL command.


Getting the count isn't too hard, but I don't want to go through each member and manually update them. That's not fun.
[php]

SELECT COUNT(post_id)
FROM `cvs_fpro_posts`
WHERE poster_id = 2[/php]
Zero2Cool  
#2 Posted : Thursday, January 6, 2011 3:49:58 AM(UTC)
[php]UPDATE table_users
SET user_posts = COUNT(*)
FROM table_fpro_posts
WHERE table_fpro_posts.poster_id = table_users.user_id[/php]

That was my first guess, but I haven't ran it ... scared I'll break shit.
Zero2Cool  
#3 Posted : Thursday, January 6, 2011 4:34:42 AM(UTC)
Code:
SELECT table_fpro_posts.poster_id, count(table_fpro_posts.poster_id), table_users.user_id, table_users.user_posts
FROM table_users LEFT JOIN table_fpro_posts
ON table_users.user_id = table_fpro_posts.poster_id
GROUP BY table_fpro_posts.poster_id


This displays the members post count on their profile, next to the actual post count.
Zero2Cool  
#4 Posted : Thursday, January 6, 2011 4:47:16 AM(UTC)
[php]UPDATE table_users
SET table_users.user_posts = (SELECT COUNT(table_fpro_posts.poster_id)
FROM table_fpro_posts
WHERE table_users.user_id = table_fpro_posts.poster_id)[/php]

This did the trick.
Zero2Cool  
#5 Posted : Saturday, January 8, 2011 4:16:05 PM(UTC)
+1
Rss Feed
Users browsing this topic
Guest
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error

Fan Shout
Zero2Cool (24-May) : Sad about Cortez Kennedy. I remember playing him in Tecmo (beast!)
Cheesey (23-May) : RIP Cortez Kennedy
Smokey (23-May) : R.I.P.Sir Rodger (007) Moore .
Smokey (23-May) : Try Fish
Porforis (22-May) : Chicken 4 dayz!
gbguy20 (22-May) : Agreed
Smokey (21-May) : Yes, I like Chick-fil-a .
Smokey (21-May) : Rabid Chicken ? LOL
rabidgopher04 (21-May) : Chick fil a
Zero2Cool (20-May) : Penguins & Bad Guys Tied 2 apiece! LETS GO PENS!
Smokey (20-May) : Who sells the best Chicken Sandwich ? Wendy, the King, McD, etc. ?
Smokey (20-May) : Just Visiting ? Join and post today !
Zero2Cool (18-May) : Screw you. (signed Pens fan)
TheKanataThrilla (18-May) : Go Sens!!! Will be in the crowd for the Friday game.
Smokey (18-May) : E.Lacy makes weight in Seattle by 2 lbs. (253 lbs.)
buckeyepackfan (17-May) : Blount signs 1 year deal with Eagles.
DarkaneRules (14-May) : and still! Miocic & Jedrzejczyk
Zero2Cool (13-May) : RP ... you mean Go Pens ... I fix for you.
RaiderPride (13-May) : Gotta Love P.K. T.K.T. I agree.. Go Preds.
Smokey (12-May) : CB Kevin King signs 4 yr deal, no 5th year option .
TheKanataThrilla (12-May) : Go Nashville in the West
TheKanataThrilla (12-May) : My son is wearing his Mario Lemieux Pens shirt and my daughter is wearing he Sens shirt. We win no matter what.
Zero2Cool (11-May) : Aaron Nagler:Packers announce first training camp practice to be held Thursday, July 27
Zero2Cool (11-May) : Capitals are dirty weak trash.
Zero2Cool (11-May) : NHL is great! PENGUINS!!!!
yooperfan (10-May) : Screw the NBA and the NHL, neither are worth watching!
wpr (10-May) : hahaha. Poor Bettman. Worth the price to see it.
TheKanataThrilla (10-May) : Bettman would blow a gasket if it was an all-Canadian finals. I want Nashville as I am a huge Mike Fisher fan.
Smokey (10-May) : Cheap Shot ? I think not .
wpr (10-May) : Thrilla how about an all Canada Finals?
TheKanataThrilla (10-May) : Pens tomorrow. Screw you Caps for the cheap shot on Crosby.
TheKanataThrilla (10-May) : Go Sens. Want to see the Sens pull it out tomorrow.
DarkaneRules (9-May) : that's a good thing. means the players are staying out of trouble
DoddPower (9-May) : awfully quiet in here
DoddPower (3-May) : darn
Please sign in to use Fan Shout
2017 Packers Schedule
Sunday, Sep 10 @ 3:25 PM
SEAHAWKS
Sunday, Sep 17 @ 7:30 PM
at Falcons
Sunday, Sep 24 @ 3:25 PM
BENGALS
Thursday, Sep 28 @ 7:25 PM
BEARS
Sunday, Oct 8 @ 3:25 PM
at Cowboys
Sunday, Oct 15 @ 12:00 PM
at Vikings
Sunday, Oct 22 @ 12:00 PM
SAINTS
Sunday, Oct 29 @ 12:00 AM
- BYE -
Monday, Nov 6 @ 7:30 PM
LIONS
Sunday, Nov 12 @ 12:00 PM
at Bears
Sunday, Nov 19 @ 12:00 PM
RAVENS
Sunday, Nov 26 @ 7:30 PM
at Steelers
Sunday, Dec 3 @ 12:00 PM
BUCCANEERS
Sunday, Dec 10 @ 12:00 PM
at Browns
Saturday, Dec 23 @ 7:30 PM
VIKINGS
Sunday, Dec 31 @ 12:00 PM
at Lions
Saturday, Dec 17 @ 12:00 PM
at Panthers
Think About It
Think About It
Recent Topics
2m / Green Bay Packers Talk / earthquake

1h / Around The NFL / Cheesey

4h / Green Bay Packers Talk / wpr

23-May / Green Bay Packers Talk / Smokey

22-May / Green Bay Packers Talk / nerdmann

22-May / Green Bay Packers Talk / Smokey

21-May / Packers Draft Threads / Smokey

20-May / Green Bay Packers Talk / Smokey

19-May / Green Bay Packers Talk / sschind

19-May / Green Bay Packers Talk / sschind

18-May / Green Bay Packers Talk / Smokey

18-May / Green Bay Packers Talk / hardrocker950

18-May / Green Bay Packers Talk / Smokey

18-May / Around The NFL / Smokey

18-May / Green Bay Packers Talk / DakotaT

Headlines