0
我有一個問題。我做了一個需要顯示多行數據庫的程序,並且在每一行都必須有一個複選框來檢查這個項目。同時,如果複選框被選中,我必須更新數據庫。要更新它,我需要2個字段值與複選框一起解析。我應該如何把場的價值?如何把多個字段的值放在一個複選框中?
HTML:
<!-- <input name="cek" <?php echo $row['STATUS_KIRIM']; echo $row['ID_NOTA_JUAL'];
echo $row['ID_BARANG'];?> id="cek<?php echo $row['STATUS_KIRIM'];?>"
type="checkbox" value="<?php echo $row['STATUS_KIRIM'];?>" <?php if ($row['STATUS_KIRIM'] == 1)
echo 'checked="checked"'; else 'checked="unchecked"';?>
/> -->
JS:
<script type="text/javascript">
$("#cek").click(function()
{
$("input").val(["$row['STATUS_KIRIM']", "$row['ID_NOTA_JUAL']", "$row['ID_BARANG']"]);
$.post("cek.php",$("input"), proses);
function proses(val[0])
{
if (val[0]=='1')
{
alert("Checked the item");
}
else
{
alert("Unchecked the item");
}
}
return false;
});
});
</script>
// cek.php
include "include/ConnDB.php";
include "include/function.php";
$idp = $_POST($row['ID_NOTA_JUAL']);
$idb = $_POST($row['ID_BARANG']);
$status = $_POST($row['STATUS_KIRIM']);
$db = new OraSQL();
$db2 = new OraSQL();
if($status == 1)
{
$db->execute("UPDATE T_ITEM SET STATUS_KIRIM=1 WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
} else {
$db->execute("UPDATE T_ITEM SET STATUS_KIRIM=0 WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
}
$query2 = sprintf("SELECT STATUS_KIRIM FROM T_ITEM WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
$result2 = $db2->query($query2);
$row2 = $result2->fetch_assoc();
if(isset($row2['STATUS_KIRIM'])) $cek=$row2['STATUS_KIRIM']; else $cek="";
echo $cek ;
?>