Help - Search - Members - Calendar
Full Version: mt_placement SQL help fixing category assignment
Movable Type Community Forum > Installing and Upgrading > Databases
takeoneonion
Hi all
I have been assigning categories to articles and I have a multi level parent child relationship

level 1
level 1.2
level 1.2.3

Currently the level 1 is set as the primary category, and the other categories as secondary.
I want the level 1.2.3 to be the primary.

when I set then via the "list and edit entries" window I can set 1.2.3 to be the primary, but as 1.2.3 is already set as a secondary then I get everything twice in the category archive.

I can see how to fix this by editing the mt_placement table, but my SQL is not strong enough to make me feel comfortable doing this.

I want to do something like the following, ideally within PHPMyAdmin.
CODE
SELECT *
FROM `mt_placement`
WHERE `placement_blog_id` =1
ORDER BY `placement_entry_id` ASC
LIMIT 0 , 30


lists the table sorted by entry, I want to identify where the same category is assigned as primary and secondary and then remove the secondary one.

so some thing like
for each placement_entry_id
list placement_category_id
if placement_category_id occurs twice for the entry
then select the one where placement_is_primary=1
and delete it.
repeat for the next entry

is this possible in SQL
any help much appreciated
thanks
Gavin
imabug
It's probably not going to be easy to do with straight SQL (might be doable though). It would be pretty easy to do with a simple PHP or Perl script though.
takeoneonion
I'm happy for this to be perl or php, if someone can give me pointers in how to write that. I can see that I'd need to grab all the placement_entry_ids and compare for each set of placement_entry_ids against the placement_category_ids and then remove the dupe.
Neither my php, nor my perl are feeling brave enough to write this though, I'm learning though...
any help much appreciated
thanks
gavin
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.