I have 2 tables:
1. posts(id, cat_id, title, contents, date_posted)
2. categories(id, name),
and to delete the category:
<a href="delete_category.php?id=<?php echo $category['id']; ?>">Delete</a>if i view the categories and try to delete one from my cat_list.php page, it deletes the category from the list, but in my posts table, the cat_id assigned to the deleted category is still there... is there a way to, upon deleting a category, update all cat_id's from all posts and set the value to '1' (Uncategorized) or something like that? Right now if I delete a category, the post still sits there with that cat_id still assigned to it.
Here is my delete function:
function delete($table, $id) { if (isset($_GET['id']) && is_numeric($_GET['id'])) { $table = mysql_real_escape_string($table); $id = (int) $id; $query = "SELECT `posts`.`id`, `categories`.`id`, FROM `posts` INNER JOIN {`categories`} ON `categories`.`id` = `posts`.`id`"; $query = "DELETE FROM `{$table}` WHERE `id` = '{$id}'"; if(mysql_query($query)) { echo 'Ok'; } else { echo 'Not Ok'; } } };I've been playing around with joins and what not but I am unsure as what to use to fix this issue. I'm not real sure what the best way to go about doing this would be. I know my sql syntax isn't correct, and I'm probably doing it wrong, but just by playing around with the code, I'm stuck :/
Any and all help is appreciated.