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 (9h) : You can do it!
Nonstopdrivel (22-Jan) : I thought Joe Buck's "makes the catch and takes a seat" line last night was hilarious.
Nonstopdrivel (22-Jan) : There are 375,000 posts in 20,903 topics in 16 forums. Very round number.
Zero2Cool (22-Jan) : Doug Pederson, former Packers backup QB helps knockout Vikings. :-)
Smokey (21-Jan) : CHAT IS WHERE IT'S AT.
Smokey (21-Jan) : The "CHAT" is very open !
dhazer (21-Jan) : Eagles 17 vikes 14
dhazer (21-Jan) : jags 24-21 withthe defense stopping Brady at the end
Smokey (21-Jan) : beast, R U picking this week ?
rabidgopher04 (20-Jan) : It sure is quiet in Packersland right now. Very unfamiliar feeling.
yooperfan (20-Jan) : The Packers have played the same game over the years.Teams just don't want to tip their hand.
Smokey (19-Jan) : Patriots playing the "Is Brady injured game", so open and transparent, NOT !
Mucky Tundra (19-Jan) : YEAH LETS GO!! Psst where are we going?
Zero2Cool (19-Jan) : LETS GO!!!
Mucky Tundra (18-Jan) : Fans wondered what he was smoking
Mucky Tundra (18-Jan) : Funny talk about Watkins, LeRoy Butler suggested a trade for him a few years ago on FB
Zero2Cool (17-Jan) : Report: Landry wants Davante Adams-type deal -
Zero2Cool (17-Jan) : Packers bring in Sammy Watkins, you will ALL shite your pants
buckeyepackfan (17-Jan) : How long till we here the fire alarms go off in the middle of the night !!!
buckeyepackfan (17-Jan) : cheatin' bastards!!!! :)
Zero2Cool (16-Jan) : Patriots have no end to what they'll do for a win!
Zero2Cool (16-Jan) : RB Leonard Fournette was involved in a minor accident today when his car was rear-ended.
Zero2Cool (16-Jan) : Packers safeties coach Darren Perry interviewing with Texans
Zero2Cool (15-Jan) : Damarious Randall has hand surgery
Cheesey (15-Jan) : Man, talk about dumb luck. The Saints defense on that last play looked like the Packers D.
Zero2Cool (15-Jan) : "Skol Vikings!" It is the team's Viking war chant ... Inspired by Iceland's national soccer team
Zero2Cool (15-Jan) : Packers not playing sure makes playoff weekend less tense.
Nonstopdrivel (15-Jan) : I am slowly recovering from cardiac arrest. What an ending. What a freaking ending!
Mucky Tundra (15-Jan) : DONT BLOW THIS NEW ORLEANS
Smokey (14-Jan) : The"CHAT" is very open !
Zero2Cool (14-Jan) : Damn Saints giving them the game
Nonstopdrivel (14-Jan) : Mariota just ran up the white flag.
Zero2Cool (14-Jan) : Titans OL not too good without Conklin
KRK (13-Jan) : Schwartz defense looking very porous
Nonstopdrivel (13-Jan) : Get yo asses in the chat room, mofrackers!
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
Sunday, Dec 17 @ 12:00 PM
at Panthers
Saturday, Dec 23 @ 7:30 PM
VIKINGS
Sunday, Dec 31 @ 12:00 PM
at Lions
Think About It
Think About It
Recent Topics
10m / Green Bay Packers Talk / wpr

42m / Green Bay Packers Talk / DoddPower

1h / Around The NFL / Cheesey

8h / Green Bay Packers Talk / Mucky Tundra

23h / Fantasy Sports Talk / Smokey

22-Jan / Green Bay Packers Talk / Zero2Cool

21-Jan / Green Bay Packers Talk / KRK

20-Jan / Green Bay Packers Talk / yooperfan

20-Jan / Green Bay Packers Talk / nerdmann

20-Jan / Green Bay Packers Talk / isocleas2

18-Jan / Green Bay Packers Talk / warhawk

18-Jan / Green Bay Packers Talk / beast

17-Jan / Green Bay Packers Talk / isocleas2

16-Jan / Fantasy Sports Talk / Nonstopdrivel

16-Jan / Green Bay Packers Talk / beast

Headlines