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
beast (10h) : Who are the longshots? Jags? Saints? Redskins? and who?
SINCITYCHEEZE (10h) : Buckeye closing in on 4 Longshots in Pickem today....Son you need to hook me up we could make a killing on some parlays next weekend. Lol
beast (11h) : Bears ran it 60% of the time...
beast (15h) : Bears tried hard to give it away, but Steelers couldn't take it
Mucky Tundra (16h) : Lot of injuries :(
Zero2Cool (16h) : OUT for the Packers: WR Randall Cobb S Kentrell Brice CB Davon House LB Jake Ryan LB Nick Perry T David Bakhtiari DT Mike Daniels
beast (17h) : Ravens/Jags must be a FF nightmare, as ol' TEs who never score, had 4 of the 6 TDs
beast (17h) : Bears beating Steelers at halftime.
beast (17h) : https://sports.vice.com/en_us/article/yp89dj/stephen-a-smith-points-out-nfls-paid-patriotism-problem
beast (17h) : I just read that it wasn't until the NFL started getting paid by the DoD (in 2009), that players were on the sidelines for the Anthem. (I ca
Zero2Cool (17h) : apparently it was comon to stay in lockeroom years ago
Zero2Cool (17h) : i couldn't find anything confirming its against the rules
beast (17h) : Is it against the rules to be in the lockerroom for the Anthem?
yooperfan (18h) : Prolly some fines coming down.
Zero2Cool (19h) : it is? this could be interesting
yooperfan (19h) : It's against league rules for a team not to be on the field during the National Anthem.
Nonstopdrivel (19h) : Chat room posting to the top instead of bottom again.
Zero2Cool (19h) : Jordy Nelson IN. Randall Cobb OUT.
Nonstopdrivel (19h) : Where is everybody? There's plenty of football to talk about!
yinzer (20h) : what??
Zero2Cool (20h) : Today's Birthdays: mi_keys (29)
Zero2Cool (20h) : Steelers Will Remain In Locker Room During National Anthem
Zero2Cool (20h) : thanks
buckeyepackfan (24-Sep) : Good Morning Packer Fans! Gameday! GO! PACK! GO!
buckeyepackfan (24-Sep) : Happy Belated Birthday Z2C!
beast (24-Sep) : Happy Birthday
wpr (23-Sep) : Hope you had a great day Z.
uffda udfa (23-Sep) : Happy Birthday, Z.
macbob (23-Sep) : Z2C-Hope you had a wonderful birthday! Thanks for providing us a great place to hang out.
Smokey (23-Sep) : Anyone watching the Utah vs Arizona tonight .
Cheesey (22-Sep) : No..."Fired FROM the forge!"LOL!
Smokey (21-Sep) : A "Forged in Fire" wash out ? LOL
Cheesey (21-Sep) : Zero got cut??? I TOLD him not to play with knives!
uffda udfa (21-Sep) : Spriggs to IR.
uffda udfa (21-Sep) : Nick Perry having surgery on finger likely out this week.
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
2h / Green Bay Packers Talk / isocleas2

2h / Green Bay Packers Talk / isocleas2

5h / Green Bay Packers Talk / wpr

5h / Green Bay Packers Talk / wpr

6h / Green Bay Packers Talk / Cheesey

8h / Green Bay Packers Talk / nerdmann

11h / Green Bay Packers Talk / beast

12h / Green Bay Packers Talk / nerdmann

23-Sep / Green Bay Packers Talk / Smokey

22-Sep / Green Bay Packers Talk / steveishere

22-Sep / Green Bay Packers Talk / DoddPower

21-Sep / Green Bay Packers Talk / nerdmann

21-Sep / Around The NFL / Cheesey

21-Sep / Green Bay Packers Talk / DoddPower

20-Sep / Green Bay Packers Talk / nerdmann

Headlines