这是我的代码:
$perbandingan = mysql_query("SELECT * FROM ar_produk_detail WHERE id_produk = '$_GET[id]'");
$rows = mysql_num_rows($perbandingan);
while($w = mysql_fetch_array($perbandingan)){
$w_id[] = $w['id_subkategori'];
$p_id[] = $w['id_produk_det'];
}
$data = $_POST['checkbox'];
$sum = count($data);
for ($r = 0; $r < $sum; $r++){
if($w_id[$r] != $data[$r]){
$do = "UPDATE FROM ar_produk_detail SET id_subkategori = '".$data[$r]."' WHERE id_produk_det = '".$p_id[$r]."'";
mysql_query($do); //Hapus yang tidak sama / tidak terpilih
echo $do;
}
}
答案 0 :(得分:2)
不应该是
UPDATE FROM ar_produk_detail SET id_subkateg
但是
"UPDATE ar_produk_detail SET id_subkateg = '".$data[$r]."' WHERE id_produk_det = '".$p_id[$r]."'";
在UPDATE查询中不需要FROM。
答案 1 :(得分:2)
$perbandingan = mysql_query("SELECT * FROM ar_produk_detail WHERE id_produk = '$_GET[id]'");
$rows = mysql_num_rows($perbandingan);
while($w = mysql_fetch_array($perbandingan)){
$w_id[] = $w['id_subkategori'];
$p_id[] = $w['id_produk_det'];
}
$data = $_POST['checkbox'];
$sum = count($data);
for ($r = 0; $r < $sum; $r++){
if($w_id[$r] != $data[$r]){
$do = mysql_query("UPDATE ar_produk_detail SET id_subkateg = '$data[$r]' WHERE id_produk_det = '$p_id[$r]'");
}
}
答案 2 :(得分:1)
$do = "UPDATE ar_produk_detail SET id_subkategori = '".$data[$r]."' WHERE id_produk_det = '".$p_id[$r]."'";
// Remove from in the query
答案 3 :(得分:0)
$ do =“UPDATE FROM ar_produk_detail SET id_subkategori ='”。$ data [$ r]。“'WHERE id_produk_det ='”。$ p_id [$ r]。“'”;
使用“FORM”查看更新查询,这是不正确的。
正确的语法 UPDATE table_name SET column1 = value1 WHERE some_column = some_value;
因此您必须从查询中删除“FROM” $ do =“UPDATE ar_produk_detail SET id_subkategori ='”。$ data [$ r]。“'WHERE id_produk_det ='”。$ p_id [$ r]。“'”;