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

Go to last post Go to first unread
#1 Posted : Friday, October 22, 2010 2:59:22 PM(UTC)
I'm trying to clean up the database.

My goal is to remove the posts from members that have been deleted.

I want a select statement that shows me how many of them there are before deleting.

I think I'll be using three tables with this.

table (field)
[ul]users (user_id)
posts (poster_id)
posts_text (post_id)[/ul]

Every post is given and id number. Then that id number is assigned to the post text.

The relationship between users and posts is the user_id and poster_id.
The relationship between posts and posts_text is the post_id.

I tried this, but it didn't work so well.

[php]SELECT *
FROM posts LEFT JOIN users
ON posts.poster_id != users.user_id[/php]

I think I caused some site load errors with this query too, lol.
#2 Posted : Friday, October 22, 2010 3:09:19 PM(UTC)
bummer you can't delete posts
#3 Posted : Friday, October 22, 2010 3:17:12 PM(UTC)
don't you want to use count

SELECT posts, COUNT(*) FROM posts WHERE Posterid=poster_id GROUP BY poster_id;

you have to play around with the table names, and you add quite a bit to a query with 'where' & 'group by' as well as 'orderby'

just running a select or count query should not break the site
#4 Posted : Friday, October 22, 2010 3:22:57 PM(UTC)
I dunno, do I?
#5 Posted : Friday, October 22, 2010 3:25:30 PM(UTC)
you know the answer, just play around till you get the query.

wanna let me in?

i'll try
otherwise this will help
#6 Posted : Friday, October 22, 2010 3:31:11 PM(UTC)
I'm confused. Are you wanting to clean up deleted posts or posts by deleted members? The owner of the other board I used to administrate did the latter routinely; unfortunately, some of the most prolific members (e.g., instructors) were getting deleted. This resulted in some of our best threads being rendered nearly indecipherable, with members responding to phantom statements and questions. Threads came to resemble Swiss cheese, with much of the best content missing, rendering them all but useless. If this is what you want to do, I'd urge caution in implementing it.
#7 Posted : Friday, October 22, 2010 3:36:19 PM(UTC)
627 posts returned.

Every post should have a valid relationship to a member.
Every topic should have a valid relationship to a post.
Every post should have a valid relationship to a topic.

I don't want rogue data out there.
#8 Posted : Friday, October 22, 2010 3:44:48 PM(UTC)
Yes use the count, cleaner approach for your request in the first post.. as a review.
#9 Posted : Friday, October 22, 2010 3:45:50 PM(UTC)
Okay.. with the timeout error, more than likely due to query gen, my comment now seems out of place. lol.
#10 Posted : Friday, October 22, 2010 3:52:22 PM(UTC)
627 is what I got back, which is just a list of members who have 1 or more posts.

The member list shows 618 with a post.

That to me means we have posts for 9 members that have been deleted.
#11 Posted : Friday, October 22, 2010 3:56:11 PM(UTC)
In the posts table, I have 13,155 posts.
The software shows 12,989.

I have 166 posts that were deleted, but not removed from the database??

Edit, actually it means I have 13,155 post ID's, but only 12,989 posts with a text.
#12 Posted : Friday, October 22, 2010 4:11:55 PM(UTC)
SELECT _fpro_posts_text.post_id
FROM _fpro_posts, _fpro_posts_text
WHERE _fpro_posts.poster_id='2'
AND _fpro_posts_text.post_id != _fpro_posts.post_id

Shouldn't this display a list of posts_text.post_id's that do not have a corresponding posts.posts_id for the poster_id 2?
#13 Posted : Friday, October 22, 2010 4:33:07 PM(UTC)
This is hopeless. There's a ton of NULL's under id 2, okay, 136 or so, but I can't delete them records!
#14 Posted : Friday, October 22, 2010 9:47:14 PM(UTC)
From what you say this forum software works like other forum software with a POSTS table, a MEMBERS/USERS table and a TOPICS table. Each of them refer to each other by an auto-incremented value (topicID, postID and memberID). If you want to delete all the posts from members that don't exist you'd have to use multiple queries. For example:



// establish variables
$memberposts = "0";
$nonmemberposts = "0";

// first query all posts
$post_query ="SELECT * FROM posts";
$post_result = mysql_query($post_query);
while($post_row = mysql_fetch_array($post_result)) {
	// now we can address each post individually
	// we should set some variables we need
	$postID = $post_row["id"];				// The post ID
	$memberID = $post_row["memberid"];		// The member that made this post
	$isMember = true;						// boolean for whether the member exists or not
	// now we need to figure out if the member with that id still exists
	// to do that you need to do a num_rows query
	$member_query = "SELECT * FROM members WHERE id='$memberID'";
	$member_count = mysql_num_rows($member_query);
	// check if it returns a result
	if($member_count < "1") {
		// the member does not exist
		$isMember = false;
	// now we return the result of our script
	if($isMember) {
		// post verified
	} else {
		// delete the post?
		// I wouldn't
		// $delete_query = "DELETE FROM posts WHERE id='$postID'";
		// mysql_query($delete_query);

// display a report at the end
echo "Total posts by members: " . $membersposts . "<br />total posts by non-members: " . $nonmemberposts;


Obviously you'll have to replace the references I make to mysql rows and tables because I don't know whats yours are exactly. But if I do understand what you want this code should work, although I haven't tested it.

EDIT: Please don't run the script with the delete query in it until you've verified that it works. I would not want you to accidentally delete all the posts in this forum because of my bad code. I've already commented the delete query out so that if you want to you can just comment it back in.
#15 Posted : Friday, October 22, 2010 10:48:33 PM(UTC)
Yeah, I don't want to delete them just yet. I want to see them first, that's why I was using the SQL query in the phpAdmin.

I can provide the three tables for you guys if that'll help.
#16 Posted : Friday, October 22, 2010 10:53:44 PM(UTC)


// $delete_query = "DELETE ?????FROM posts WHERE id='$postID'";
		// mysql_query($delete_query);

wouldn't work if it wasn't commented out, this would cause an error, not telling what you want to delete.

why don't you just delete id #2, the whole row? if you are using auto increment for the id field, it wouldn't let you delete the row unless you delete the id
#17 Posted : Friday, October 22, 2010 10:58:03 PM(UTC)
I've deleted members in the users table, but not their posts. Therefore there's posts out there that cause errors while searching.
#18 Posted : Friday, October 22, 2010 11:23:58 PM(UTC)
imo, the best way to maintain your site would be to manually go into the database through php admin and delete the rows that way.

a script would be nice for maintenance, but you are risking wiping out data you want to keep.

just wondering, did you join the mysql forum. you should, and post questions in the forum.

you'll get your solution...if you are driven.

BTW..I find it humorous, a .NET Developer is running his forum using PHP, Microsoft's main nemesis.

Isn't that like sayin you work at Ford but drive a Toyota?

:icon_smile: just sayin!
#19 Posted : Saturday, October 23, 2010 12:08:55 AM(UTC)
I was looking into developing my own software using ASP-MVC2 with SQL Server, but it seems like too much work. I'd be reinventing a lot of the options here.

Might as well stick with this and enhance it, instead of recreating everything, right?
#20 Posted : Saturday, October 23, 2010 2:55:39 AM(UTC)
yes, stick with the PHP site. Classic ASP is an old technology. You have to write a ridiculous amount of "spaghetti" code to do even a simple database call.

Microsoft updated to .NET for a reason!
Rss Feed
Users browsing this topic
2 Pages12>
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.



Fan Shout
Zero2Cool (4h) : Packers’ 2018 draft class will only take up about $2.9M in salary cap space thanks to the Top 51 rule
Porforis (6h) : Holy crap I'll be turning 9 in PackersHome years this year.
Zero2Cool (8h) : rock on!!
DarkaneRules (8h) : I'm celebrating 10 years at PackersHome this year.
Zero2Cool (8h) : Damn, Jared you one old ass dude.
Zero2Cool (8h) : Today's Birthdays: jdlax (115)
Zero2Cool (8h) : 1 year with Aaron Rodgers and having monster stats = GET PAID STRAIGHT CASH HOMIE
DarkaneRules (8h) : I doubt he'll take a deal like that. He wants to get paid like the other WRs have.
Zero2Cool (8h) : I would pay 2.99 million base, then incentives! INCENTIVES!!!
DarkaneRules (8h) : hah, funny how that happens in this sport. See what the market says. I wouldn't pay over 3mil.
Zero2Cool (8h) : What's the guys height Draft profile says six one, everything else says six three
Zero2Cool (8h) : You can do it!
Zero2Cool (8h) : PROVE IT
DarkaneRules (8h) : Not unless he'll take a 1-yr prove it deal on the cheap.
Zero2Cool (9h) : WR Allen Hurns will be released by the Jaguars. SIGN HIM
packerfanoutwest (12h) : Burnett signing with the Steelers?
Zero2Cool (19-Mar) : Three years, $30 million could turn into one year, $13 million for Jimmy Graham
DarkaneRules (18-Mar) : to*
DarkaneRules (18-Mar) : Whatever happens, we've got to get Josh move near the LOS where he belongs.
TheKanataThrilla (18-Mar) : Would we consider trying Rollins a S?
gbguy20 (18-Mar) : so what's the deal then, are we to expect to see josh Jones in Morgan Burnetts spot this season? i guess I can't say I'm opposed to the idea.
Smokey (17-Mar) : BG is in no hurry to anounce a new Rodgers deal. Smart !
gbguy20 (17-Mar) : When is Rodgers signing that extension that was supposedly only awaiting Kirk? Typing on a phone makes things tough.
Nonstopdrivel (17-Mar) : That's what I was thinking: I wasn't aware that he was quitting.
Zero2Cool (17-Mar) : Hopefully not for a long time. We need him.
gbguy20 (17-Mar) : when is 12 resigning
Nonstopdrivel (17-Mar) : I have to say I like it, even if it means I have to put up with occasional ads for Maseratis. 😂
Nonstopdrivel (17-Mar) : Interestingly, since I blocked third-party cookies, ads I see tend to relate to the content of the page instead of my most recent Amazon searches.
TheKanataThrilla (17-Mar) : Mathieu to Texans? I thought he wanted to go to a play that was all about winning football games?
hardrocker950 (17-Mar) : Bears already matched
Zero2Cool (16-Mar) : Bears will certainly match it though. Maybe restructure after year one?
Zero2Cool (16-Mar) : but bears got lots of money, didn't think anyone would make the offer
Zero2Cool (16-Mar) : good question
Nonstopdrivel (16-Mar) : Can another team come and big even higher, or is it a one-off thing?
Zero2Cool (16-Mar) : Bears WILL match the Kyle Fuller offer, but still, good move.
Please sign in to use Fan Shout
2017 Packers Schedule
Sunday, Sep 10 @ 3:25 PM
Sunday, Sep 17 @ 7:30 PM
at Falcons
Sunday, Sep 24 @ 3:25 PM
Thursday, Sep 28 @ 7:25 PM
Sunday, Oct 8 @ 3:25 PM
at Cowboys
Sunday, Oct 15 @ 12:00 PM
at Vikings
Sunday, Oct 22 @ 12:00 PM
Sunday, Oct 29 @ 12:00 AM
- BYE -
Monday, Nov 6 @ 7:30 PM
Sunday, Nov 12 @ 12:00 PM
at Bears
Sunday, Nov 19 @ 12:00 PM
Sunday, Nov 26 @ 7:30 PM
at Steelers
Sunday, Dec 3 @ 12:00 PM
Sunday, Dec 10 @ 12:00 PM
at Browns
Sunday, Dec 17 @ 12:00 PM
at Panthers
Saturday, Dec 23 @ 7:30 PM
Sunday, Dec 31 @ 12:00 PM
at Lions
Think About It
Think About It
Recent Topics
5m / Green Bay Packers Talk / gbguy20

1h / Random Babble / wpr

1h / Green Bay Packers Talk / KRK

2h / Green Bay Packers Talk / beast

2h / Green Bay Packers Talk / beast

2h / Green Bay Packers Talk / Cheesey

2h / Green Bay Packers Talk / warhawk

15h / Around The NFL / Smokey

19-Mar / Green Bay Packers Talk / isocleas2

19-Mar / Green Bay Packers Talk / gbguy20

18-Mar / Green Bay Packers Talk / nyrpack

18-Mar / Green Bay Packers Talk / Cheesey

17-Mar / Green Bay Packers Talk / Cheesey

16-Mar / Random Babble / Smokey

16-Mar / Green Bay Packers Talk / beast