Removing unused tags from DB-> Compare Arrays
Posted: Fri Nov 14, 2008 5:47 am
I'm trying to determine the best way to remove tags that are no longer used in by a blog post from my database table.
Essentially tags are received by the server in the following format when a form is used for editing an existing post (note I've simply converted $_POST to actual values to keep it simple)...
If you take a moment to compare the values in both variables it's clear that in this procedure that we'll want to delete the MySQL row that contains the value JavaScript (in the relational table).
There are most likely numerous ways to approach this with the most confusing and least efficient most likely being my initial attempts. I've been thinking of converting these variables in to arrays (is there a nice PHP function to convert a nicely formatted variable or will we have to explode first?) and then using a loop (obviously) to compare the arrays. Then during the loop use something along the lines of the in_array function to determine if it's !in_array and then to queue it in to a MySQL query that I'll delete all of the removed tags from the database after the loop.
That is at least how I am thinking of approaching this task so I'm open to suggestions please!
Essentially tags are received by the server in the following format when a form is used for editing an existing post (note I've simply converted $_POST to actual values to keep it simple)...
Code: Select all
$thread_tags = 'application/xhtml+xml, XML, XHTML, CSS';
$thread_tags_old = 'application/xhtml+xml, XML, XHTML, CSS, JavaScript';There are most likely numerous ways to approach this with the most confusing and least efficient most likely being my initial attempts. I've been thinking of converting these variables in to arrays (is there a nice PHP function to convert a nicely formatted variable or will we have to explode first?) and then using a loop (obviously) to compare the arrays. Then during the loop use something along the lines of the in_array function to determine if it's !in_array and then to queue it in to a MySQL query that I'll delete all of the removed tags from the database after the loop.
That is at least how I am thinking of approaching this task so I'm open to suggestions please!