UnknownPlayer Posted April 6, 2011 Share Posted April 6, 2011 Hi, i need help with command to delete id from episodes and episode_links, when delete season.. I have this table: Season(for tv shows): where i have id, name, date fields Episodes: where i have id, season_id, name, date fields Episode_links: where i have id, episode_id, link, date fields Now i need help with command, when i delete season with id 1, to delete episodes where season_id is 1 and to delete episode_links where episode_id is id from table episodes where season_id = 1 ? If you understand me, please help me ? I tried with this: $season = $_GET['season']; $query = "DELETE FROM seasons WHERE id = '$season'"; $result = mysql_query($query, $connection); if ($result) { $query = "DELETE FROM episodes e, episode_links l WHERE e.season_id = '$season' AND l.episode_id = e.id"; $result = mysql_query($query, $connection); } but it doesn't work :/ Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 6, 2011 Share Posted April 6, 2011 you may have to do a SELECT query to establish an array of all the existing rows that fall into those constants.. then run a delete on a per row basis using the results from your SELECT Query.. Or build a long delete query dynamicly through the results of the SELECT then run a single query with the delete that way. Quote Link to comment Share on other sites More sharing options...
UnknownPlayer Posted April 6, 2011 Author Share Posted April 6, 2011 I made a foreign key and now it works.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.