Jump to content

update post with multiple categories


mraza

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.