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 :/ Link to comment https://forums.phpfreaks.com/topic/232915-delete-subs-help/ 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. Link to comment https://forums.phpfreaks.com/topic/232915-delete-subs-help/#findComment-1197938 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.. Link to comment https://forums.phpfreaks.com/topic/232915-delete-subs-help/#findComment-1197948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.