How to Delete Authors without a Penname from Your Database

Managing your articles within Article Dashboard

How to Delete Authors without a Penname from Your Database

Postby GardenSimply » Sun Oct 19, 2008 4:32 am

Solution by Marvin (http://www.upublish.info/)

I'm sure that many of you long standing site owners, know that there are many author accounts in your database with no penname associated with them. Here is a SQL query that will delete them.

You'll have to work in your myphpadmin section of your database for this ... but a php script could be written to do this as well.

***NOTE***
Its always a very good idea to backup your database before attempting any queries!!!!

In your myphpadmin, for your AD database, select SQL to run a query.

The first query below will give you a list of all the author accounts that have signed up with your directory but have no penname associated with that account.


Code: Select all
SELECT * FROM prefix_users WHERE user_id not in
(SELECT user_id FROM prefix_penname)


Note that if you are not using the "prefix_" beginning for your table names, just substitute what you ARE using.
Now as mentioned the above will give you all the accounts without pennames.

To delete all of those accounts at once ... simply do another SQL query and run the following:

Code: Select all
DELETE FROM prefix_users WHERE user_id not in
(SELECT user_id FROM prefix_penname)


Now all of those accounts are gone.
A word of warning ... if you do the above query, you will delete ALL accounts without pennames ... but you may have some recent signups that have not had a chance to put in their penname yet.

To remedy that, look at the user_id of the last author that signed up recently ... say its 1253. Do a similar query to delete authors without pennames, but only delete the one's with an id less than 1000. This still allows the last 253 accounts a chance to add a penname. The query that you will use would then be:

Code: Select all
DELETE FROM prefix_users WHERE user_id not in
(SELECT user_id FROM prefix_penname) AND user_id < 1000


You can use whatever user_id limiter value you wish by just changing that 1000 number to a larger or smaller value ... depending upon how much you want to clear from your database.

Question:
I'm just curious... Why would you want to delete authors just because they don't have a pen name?


Answer: Of course there are a variety of reasons ...
They take up space in the database.
If you rarely email authors you'd probably like to be contacting the ones that have at least made a proper penname for their account.

Question:
Could you provide one that would delete authors with no articles?


Answer:

What one has to keep in mind that it may be a two step process. Remember that articles have a penname and userid (author account) associated with them. You would want to first delete pennames that do not have an article written under them first. Then after that process, delete authors without the pennames (as written in the first post).

This way, an author may have 5 pennames, of which 2 have no articles ... those 2 pennames could be deleted ... but the author account would not be deleted afterwards, because it has 3 pennames with articles.

Delete pennames with no articles associated

Code: Select all
DELETE FROM prefix_penname WHERE pen_id not in
(SELECT penname_id FROM prefix_articles)


But as before you may wish to put a limit on pennames deleted so you are not deleting your latest pennames that haven't had a chance to create an article yet.

Code: Select all
DELETE FROM prefix_penname WHERE pen_id not in
(SELECT penname_id FROM prefix_articles) AND pen_id < xxxx


Just replace the xxxx with a number ... let's say your latest penname has a pen_id of 1000 ... you may want to delete pennames up to the pen_id of 900 giving the last pennames a chance to input an article.


If you so choose, after deleting these pennames, you can then delete the author accounts by using the previous query above (first post of this topic).
User avatar
GardenSimply
Admin
 
Posts: 208
Joined: Sat Sep 15, 2007 10:31 am
Location: Oklahoma

Re: How to Delete Authors without a Penname from Your Database

Postby joebrochin » Sun Nov 09, 2008 2:07 pm

Keep getting syntax errors and yes I removed the prefix statement and used the proper name of the tables.

Ideas???
joebrochin
Active Member
 
Posts: 121
Joined: Mon Sep 17, 2007 7:16 pm
Location: Jacksonville, NC

Re: How to Delete Authors without a Penname from Your Database

Postby GardenSimply » Mon Nov 10, 2008 2:18 am

Joe,

On which function?
User avatar
GardenSimply
Admin
 
Posts: 208
Joined: Sat Sep 15, 2007 10:31 am
Location: Oklahoma

Re: How to Delete Authors without a Penname from Your Database

Postby joebrochin » Mon Nov 10, 2008 7:36 am

Hi Jodi,

I tried the first three functions and it kept giving me the sysntax error message (#1064 if I remember correctly) and said to reference the manual for my version of MySql.

I referenced an online version and it was obviously written by database programmers FOR database programmers. :roll:
joebrochin
Active Member
 
Posts: 121
Joined: Mon Sep 17, 2007 7:16 pm
Location: Jacksonville, NC

Re: How to Delete Authors without a Penname from Your Database

Postby GardenSimply » Tue Nov 11, 2008 6:30 pm

What version of MySQL are you using? To find out, when you login to PHPMyAdmin, and click on your database, you'll see the version of MySQL on the left and the Client API version (which will be different) on your right... I don't see how this makes a real difference, I've run the code on two different versions of MySQL, but if it is older, who knows...? Let's look and see how old your version is. I've run it on a 4. something version and 5.
User avatar
GardenSimply
Admin
 
Posts: 208
Joined: Sat Sep 15, 2007 10:31 am
Location: Oklahoma

Re: How to Delete Authors without a Penname from Your Database

Postby joebrochin » Tue Nov 11, 2008 9:20 pm

Hi Jodi,

Below is what I have:
Server version: 4.0.27-standard
MySQL client version: 4.1.22
joebrochin
Active Member
 
Posts: 121
Joined: Mon Sep 17, 2007 7:16 pm
Location: Jacksonville, NC

Re: How to Delete Authors without a Penname from Your Database

Postby GardenSimply » Wed Nov 19, 2008 8:40 am

Joe,

Sorry for taking so long. I've had grandkids all week! I can't seem to get a thing done with them here. Their naps are my naps, you know what I mean? LOL

Well, your versions aren't overly new, so this shouldn't have an issue running. I haven't tried it on 4.0 (that is an old production release) 4.1 is in production and 5. is still beta, but we've been using it for over a year almost without incident. It could be that is the issue. Does your host offer hosting on a newer version?
User avatar
GardenSimply
Admin
 
Posts: 208
Joined: Sat Sep 15, 2007 10:31 am
Location: Oklahoma

Re: How to Delete Authors without a Penname from Your Database

Postby marvinko » Wed Nov 19, 2008 4:08 pm

Well I'm going to chime in here with a suggestion since this was my contribution a while back.

Jodi is correct that your mysql version is a little dated. We are running version 5.x for mysql and there are a few minor differences from the 4.x versions.

For this particular topic ... the code below (as in the original posting above):

Code: Select all
DELETE FROM prefix_users WHERE user_id not in
(SELECT user_id FROM prefix_penname) AND user_id < 1000


... does work in mysql version 5.x ... but for earlier versions (ie 4.x) try the code below:

Code: Select all
DELETE FROM 'prefix_users' WHERE 'user_id' not in
(SELECT 'user_id' FROM 'prefix_penname') AND 'user_id' < 1000


... all that has been done is adding single quotes about the table parameters. If it works ... great! If not ... depending upon the specific mysql version it may be necessary to make those single quotes ... as double quotes.

Its just something that may take a little trial and error ... and when I say error ... if doing a sql query that your mysql doesn't like ... you'll get an error and the query won't generate.

Hope that helps a little.

I would test this myself, but I don't have access to any mysql 4.x databases anymore.
marvinko
New Member
 
Posts: 13
Joined: Mon Sep 24, 2007 11:58 am


Return to Article Management in AD

Who is online

Users browsing this forum: No registered users and 1 guest

cron