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
Smokey (8h) : Guest ? Join us Today !
Smokey (9h) : Saturday , it's PIZZA NIGHT !
Smokey (23-Jun) : Friday is Seafood day , not Pizza night . Eat a Shrimp !
Cheesey (23-Jun) : Happy B-day rocker!
Zero2Cool (22-Jun) : Today's Birthdays: hardrocker950 (33)
Smokey (22-Jun) : Coffee anyone ?
Smokey (21-Jun) : good show
Cheesey (21-Jun) : APPLE with ice cream!
Smokey (20-Jun) : Cherry with Vanilla Ice Cream !!
Cheesey (20-Jun) : APPLE!
Smokey (20-Jun) : Apple or Cherry Pie ?
TheKanataThrilla (18-Jun) : The only have 2 preseason games. I like that as the fans get to see more of the starters.
TheKanataThrilla (18-Jun) : Next week I believe the CFL season starts. Go Redblacks!!!
Smokey (18-Jun) : Been researching CFL , Edmonton Eskimos have the best colors/uniforms .
Smokey (18-Jun) : When does the CFL Season start anyway ?
Smokey (18-Jun) : Saw Flute CFL highlights in the day, full CFL game was /is rare .
TheKanataThrilla (18-Jun) : I wish many of you would have seen Doug Flutie in the CFL. Absolute beauty.
TheKanataThrilla (18-Jun) : Vince Young cut from Sask. Roughriders. Good for him to consider the CFL, but only a select few NFL QB castoffs are a good CFL fit.
Smokey (17-Jun) : R 2
Zero2Cool (17-Jun) : Not all hackers are bad
Smokey (16-Jun) : Public Hangings for Hackers .
Cheesey (16-Jun) : No, he said HACKERS!
Smokey (16-Jun) : Did you say Crackers ?
Zero2Cool (16-Jun) : PACKERS PACKERS PACKERS
Cheesey (16-Jun) : "That is true, my dear Smokey!"LOL!
Smokey (15-Jun) : dat ? Brer Cheesey ?
Cheesey (15-Jun) : True dat, Smokey. MUCH better!
Smokey (15-Jun) : I like the fillets/tenders, they usually are a better deal.
Cheesey (15-Jun) : Good one, Porforis! Made me laugh!
Porforis (15-Jun) : Shoulda gone with Kentucky Fried Chickadee
Cheesey (15-Jun) : Last time I had KFC, the pieces were so small it should be renamed "Kentucky Fried Sparrow"
Cheesey (15-Jun) : POPEYES! (Or Churches chicken)
Smokey (15-Jun) : KFC or Popeyes Chicken ?
Smokey (15-Jun) : It's grocery shopping day !
Smokey (15-Jun) : Why did they shelter ?
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
3h / Green Bay Packers Talk / buckeyepackfan

4h / Green Bay Packers Talk / beast

4h / Green Bay Packers Talk / beast

10h / Green Bay Packers Talk / beast

10h / Green Bay Packers Talk / beast

11h / Green Bay Packers Talk / beast

23h / Green Bay Packers Talk / beast

23h / Green Bay Packers Talk / isocleas2

24-Jun / Around The NFL / beast

23-Jun / Green Bay Packers Talk / beast

23-Jun / Around The NFL / Smokey

23-Jun / Green Bay Packers Talk / sschind

23-Jun / Green Bay Packers Talk / sschind

23-Jun / Green Bay Packers Talk / sschind

22-Jun / Around The NFL / Smokey

Headlines