mraza Posted September 21, 2010 Share Posted September 21, 2010 hi i was working on a code where i need to use multiple categories for a post, i get help before to add post in multi categories, now i need help on what would be my query to do update for a multiple categories post, to insert a new post with multiple categories i used this $values = array(); foreach($_POST['categories'] as $catID) { $values[] = "($postID, $catID)"; } $sql = "INSERT INTO `relation` (`postid`, `catid`) VALUES " . implode(', ', $values); $query = $db->query($sql); so if a post had 3 categories it will add in relation table, now i wants to update that post and modify the categories, all other part is done only problem is to update this relational category table which have two columns only associated with post. i tried like this but did not work $sql = "UPDATE relation SET `catid` = " . implode(', ', $values) . " WHERE postid ='$id' "; please any help Quote Link to comment Share on other sites More sharing options...
mraza Posted September 22, 2010 Author Share Posted September 22, 2010 nvm i got it sorted by deleting those entries and then entering new one $sql = "DELETE FROM relation WHERE postid= $id" ; // then insert 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.