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 Link to comment https://forums.phpfreaks.com/topic/214055-update-post-with-multiple-categories/ 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 Link to comment https://forums.phpfreaks.com/topic/214055-update-post-with-multiple-categories/#findComment-1113911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.