<?php
include('config.php');

$sc_autoid 	= $_POST['sc_autoid'];
$penerbit 	= $_POST['penerbit'];
$row 		= $_POST['row'];

for($i=0;$i<$row;$i++){
	$pm_autoid = $_POST['pm_autoid'.$i];
	$category = explode(',',$_POST['sc_autoid'.$i]);
	$pc_autoid = $category[0];
	$sc_autoid = $category[1];
		
	$featured_flag = $_POST['featured_flag'.$i];
	
	
	$conn->query("delete from dl_product_category where product_id = '$pm_autoid'");
	
	$update = "INSERT INTO dl_product_category (product_id,sc_autoid,pc_autoid) values ('$pm_autoid','$sc_autoid','$pc_autoid')";
	$conn->query($update) or die($update);

	$sqlchk = "SELECT COUNT(*) as num FROM dl_product_category WHERE product_id = '$pm_autoid'";
	$chk_con = $conn->query($sqlchk) or die($sqlchk);
	$rschk = $chk_con->fetch_assoc();
	
	
	$update_mst = "UPDATE mst_product SET featured_flag = '$featured_flag' WHERE pm_autoid = '$pm_autoid'";
		$conn->query($update_mst) or die($update_mst);
	


}

	


		header('Location:update_kategori?penerbit='.$penerbit);


?>