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

Options
Go to last post Go to first unread
Zero2Cool  
#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.
dhpackr  
#2 Posted : Friday, October 22, 2010 3:09:19 PM(UTC)
bummer you can't delete posts
dhpackr  
#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
Zero2Cool  
#4 Posted : Friday, October 22, 2010 3:22:57 PM(UTC)
I dunno, do I?
dhpackr  
#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
Nonstopdrivel  
#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.
Zero2Cool  
#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.
Pack93z  
#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.
Pack93z  
#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.
Zero2Cool  
#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.
Zero2Cool  
#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.
Zero2Cool  
#12 Posted : Friday, October 22, 2010 4:11:55 PM(UTC)
[php]
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
[/php]

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?
Zero2Cool  
#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!
djcubez  
#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:

Code:

<?php

// 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
		$memberposts++;
	} else {
		// delete the post?
		// I wouldn't
		// $delete_query = "DELETE FROM posts WHERE id='$postID'";
		// mysql_query($delete_query);
		$nonmemberposts++;	
	}
}

// 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.
Zero2Cool  
#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.
dhpackr  
#16 Posted : Friday, October 22, 2010 10:53:44 PM(UTC)
Code:

<?php

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


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
Zero2Cool  
#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.
dhpackr  
#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!
Zero2Cool  
#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?
dhpackr  
#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
Guest
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.

Notification

Icon
Error

Fan Shout
gbguy20 (19h) : doesn't seem to have helped his cause much
Zero2Cool (25-May) : Aaron Rodgers spoke with Falcons GM Thomas Dimitroff at an airport telling him to sign Matt Ryan
Zero2Cool (25-May) : Rodgers said, "We don't know each other that well, but just get this deal done with Matt first so I can get on with my life."
Zero2Cool (25-May) : Isn't it Laurel after three tries?
wpr (25-May) : Yanny. If it takes 3 tries it isn't worth it
wpr (25-May) : Damnit. Bit in the butt by Auto correct
wpr (25-May) : When Gianni's pronounced it it sounded like"Tammy"
beast (25-May) : Nonstop got it correct, but when Giannis said it, the Ant-teh-toh comes out very quickly, which is said to sound very "inauthentic" when english speakers try to speed it up, but natural to native Yoru
beast (25-May) : I just read an article (with videos) on how to say it... I might be able to say it the English way, but no way I can pronounce it like Giannis himself did.
Nonstopdrivel (25-May) : Ant teh toh koonm po (roughly)
Zero2Cool (25-May) : well if it's not t hat hard to say, then ...
Nonstopdrivel (25-May) : Assuming the name is Greek, it's not t hat hard to say.
Zero2Cool (25-May) : I don't even try his last name lol
beast (25-May) : Richie Incognito told police he’s involved with the NSA, being tracked by government
beast (25-May) : Can people say Giannis Antetokounmpo's name correctly? :P
Zero2Cool (24-May) : Giannis Antetokounmpo earns All-NBA honors
Zero2Cool (24-May) : Brewers (31-19, .620), off to their best 50-game start in franchise history, own the best record in the National League
Zero2Cool (24-May) : says they shouldn't profit while anthem being played
Zero2Cool (24-May) : 49ers closing concessions during anthem.
Zero2Cool (24-May) : Muhammad Wilkerson's top reason for signing with Packers: 'Aaron Rodgers'
Zero2Cool (24-May) : 2.5lbs ones anyway ... anything else is just showing off
Zero2Cool (24-May) : I can throw dumbells too!
beast (23-May) : Richie Incognito is being held for an involuntary mental evaluation after he was accused of throwing a dumbbell at another person
Nonstopdrivel (23-May) : Weird, I thought they had parted ways with him already. Apparently he was just on IR.
Zero2Cool (23-May) : Packers expected to visit with veteran tight end Marcedes Lewis
DarkaneRules (23-May) : And whether any improvement will be enough to make the team.
DarkaneRules (23-May) : Goodson wasn't very good but it's been a while. He gets an opportunity to show how he's improved.
Zero2Cool (23-May) : I still say Goodson is trash.
Zero2Cool (23-May) : Aaron Rodgers brought up CB Demetri Goodson unprompted on Tuesday. "He's made some plays already during the two days (of OTAs)."
beast (23-May) : Black 21.5" 5ms Widescreen LED Backlight‎
Zero2Cool (23-May) : VA2246M-LED
beast (22-May) : LB Mychal Kendricks anybody? ... good speed LB... and hoping he doesn't want to go play with his brother on the Vikings
Zero2Cool (22-May) : players picked from Nos. 1 to 21 in the first round receive fully guaranteed contracts.
beast (21-May) : Rumor is that Richie Incognito wants to retire, he just wanted to be released first so that he didn't have to play back any of his signing bonus.
Zero2Cool (21-May) : Bills have released G Richie Incognito -->>> ?? Packers?
Please sign in to use Fan Shout
2018 Packers Schedule
Sunday, Sep 9 @ 7:20 PM
BEARS
Sunday, Sep 16 @ 12:00 PM
VIKINGS
Sunday, Sep 23 @ 12:00 PM
Redskins
Sunday, Sep 30 @ 12:00 PM
BILLS
Sunday, Oct 7 @ 12:00 PM
Lions
Monday, Oct 15 @ 7:15 PM
49ERS
Sunday, Oct 28 @ 3:25 PM
Rams
Sunday, Nov 4 @ 7:20 PM
Patriots
Sunday, Nov 11 @ 12:00 PM
DOLPHINS
Thursday, Nov 15 @ 7:20 PM
Seahawks
Sunday, Nov 25 @ 7:20 PM
Vikings
Sunday, Dec 2 @ 12:00 PM
CARDINALS
Sunday, Dec 9 @ 12:00 PM
FALCONS
Sunday, Dec 16 @ 12:00 PM
Bears
Sunday, Dec 23 @ 12:00 PM
Jets
Sunday, Dec 30 @ 12:00 PM
LIONS
Think About It
Think About It
Recent Topics
20m / Green Bay Packers Talk / beast

32m / Green Bay Packers Talk / beast

2h / Green Bay Packers Talk / beast

2h / Green Bay Packers Talk / Cheesey

2h / Green Bay Packers Talk / Cheesey

3h / Green Bay Packers Talk / beast

15h / Green Bay Packers Talk / beast

23h / Green Bay Packers Talk / Nonstopdrivel

25-May / Random Babble / Nonstopdrivel

25-May / Green Bay Packers Talk / Nonstopdrivel

24-May / Green Bay Packers Talk / Nonstopdrivel

24-May / Green Bay Packers Talk / Cheesey

24-May / Green Bay Packers Talk / Cheesey

22-May / Green Bay Packers Talk / nerdmann

22-May / Green Bay Packers Talk / nerdmann

Headlines