Jump to content

Archived

This topic is now archived and is closed to further replies.

Leburn

How to delete DB entries based on LIKE clauses

Recommended Posts

Hey guys,

I have a minor problem here. I run a Hockey website where I use a script to parse the stats into the DB. Unfortunately, the Forward and Goaltender stats are stuck together. What I do currently is use 2 tables: 1 for Forwards and the other for Goaltenders, that's not the problem. My problem is my script parses the Forwards into the Goaltender table and vice versa. To combat this I have my script rename the position category to 'A'. By doing this, it allows me to use phpAdmin to use the search to find all entries with position 'A' and then delete the entries accordingly. I then remove duplicate entries afterwards based on the playername category.

[hr]

Anyways my question is how can I create a script that uses a mysql query to do the following:

1. search table players for 'A' in category 'pos'
2. delete all entries (rows) that have 'A' in category 'pos'
3. delete duplicate entries based on category 'playername'

If someone can make me this script, I can then duplicate it for the goalie table myself.

Share this post


Link to post
Share on other sites
1 & 2 -- DELETE * FROM yourTable WHERE pos ='A'
3 -- Not that I'm sure why you're getting duplicates, but you can use a unique index to prevent these records from being added in the first place.

Share this post


Link to post
Share on other sites
Well first I should tell you what my site is about.

It is a Fantasy based Hockey League using real players and teams (although we have contracted/added real teams). We use a text-based simulator called FHL Sim (Fantasy Hockey League Simulator) available @ www.fhlsim.com.

This sim is basically takes the life of a GM were you trade, draft, sign, release players. Your ultimate goal is obviously to win the Cup. Basically consider it the manager part of the EA Sports NHL series, but with 30 real GMs.

One of the nice features is the simulator outputs the statistics to html pages.

Now what I do is use a script to parse the data from these pages and place them into a DB. The script looks through the html source code to find the various stats.

I personally did not make the script from scratch, I was fortunate enough to have someone else send me a sample, which I then worked on for my league.
[hr]
Now I think one of the duplicate issues is the fact that some players play for more than one team and therefore have 2 or more entries. The only issue here is for the current season stats, were all I care about is the latest entry for each player. However, I believe this issue will be resolved in our upcoming season as we will be doing the transactions differently.

Anyways, if you want to check out some examples of what I am talking about feel free to reply here, and I can post a few links to the stat pages, my parsing script, etc.

Share this post


Link to post
Share on other sites
That doesn't change anything -- you'll have to decide which of the duplicates you want to keep.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.