You are not logged in. Join Free! | Log In Thank you!    

Welcome to your Green Bay Packers Online Community!

Since 2006, PackersHome has been providing a unique experience for fans.
Your participation is greatly anticipated!
Login or Register.

Notification

Icon
Error

2 Pages12>
Share
Options
View
Go to last post Go to first unread
Offline Zero2Cool  
#1 Posted : Friday, October 22, 2010 2:59:22 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

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.

UserPostedImage
Click here and find the LATEST Packers News!
Sponsor
Offline dhpackr  
#2 Posted : Friday, October 22, 2010 3:09:19 PM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

bummer you can't delete posts
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline dhpackr  
#3 Posted : Friday, October 22, 2010 3:17:12 PM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

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
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Zero2Cool  
#4 Posted : Friday, October 22, 2010 3:22:57 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

I dunno, do I?

UserPostedImage
Click here and find the LATEST Packers News!
Offline dhpackr  
#5 Posted : Friday, October 22, 2010 3:25:30 PM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

you know the answer, just play around till you get the query.

wanna let me in?

i'll try
otherwise this will help
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Nonstopdrivel  
#6 Posted : Friday, October 22, 2010 3:31:11 PM(UTC)
Nonstopdrivel

Rank: Hall of Famer

United States
Posts: 11,691
Joined: 9/14/2008(UTC)
Location: Germany

Applause Given: 365
Applause Received: 263

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.
UserPostedImage
Offline Zero2Cool  
#7 Posted : Friday, October 22, 2010 3:36:19 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

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.

UserPostedImage
Click here and find the LATEST Packers News!
Offline Pack93z  
#8 Posted : Friday, October 22, 2010 3:44:48 PM(UTC)
Pack93z

Rank: Hall of Famer

U.S. Minor Islands
Posts: 12,600
Joined: 3/16/2007(UTC)
Location: North Central Wisconsin

Applause Given: 351
Applause Received: 932

Yes use the count, cleaner approach for your request in the first post.. as a review.
The wolves will never lose sleep over the feelings of the sheep.

UserPostedImage
Offline Pack93z  
#9 Posted : Friday, October 22, 2010 3:45:50 PM(UTC)
Pack93z

Rank: Hall of Famer

U.S. Minor Islands
Posts: 12,600
Joined: 3/16/2007(UTC)
Location: North Central Wisconsin

Applause Given: 351
Applause Received: 932

Okay.. with the timeout error, more than likely due to query gen, my comment now seems out of place. lol.
The wolves will never lose sleep over the feelings of the sheep.

UserPostedImage
Offline Zero2Cool  
#10 Posted : Friday, October 22, 2010 3:52:22 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

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.

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#11 Posted : Friday, October 22, 2010 3:56:11 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

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.

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#12 Posted : Friday, October 22, 2010 4:11:55 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

[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?

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#13 Posted : Friday, October 22, 2010 4:33:07 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

This is hopeless. There's a ton of NULL's under id 2, okay, 136 or so, but I can't delete them records!

UserPostedImage
Click here and find the LATEST Packers News!
Offline djcubez  
#14 Posted : Friday, October 22, 2010 9:47:14 PM(UTC)
djcubez

Rank: 2nd Round Draft Pick

Posts: 1,750
Joined: 8/7/2008(UTC)
Location: Milwaukee

Applause Given: 8
Applause Received: 13

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.
Check out my music webpage - Click Here
Offline Zero2Cool  
#15 Posted : Friday, October 22, 2010 10:48:33 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,220
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,738
Applause Received: 1,784

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.

UserPostedImage
Click here and find the LATEST Packers News!
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.

Powered by YAF 2.1.0 | YAF © 2003-2014, Yet Another Forum.NET
This page was generated in 0.629 seconds.