我有问题。我制作了一个程序,需要显示多行数据库,每行必须有一个复选框来检查项目。同时,如果选中复选框,我必须更新数据库。要更新它,我需要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 ;
?>
答案 0 :(得分:0)
使用<input type="hidden"/>
获取额外值。您必须给他们一些您可以轻松找到的名称,但这将是最简单的解决方案。如果您愿意,也可以使用字符串化的JSON作为复选框值,但是您还必须处理JSON读/写。