我必须将 2 个 id-s 放在一起$_POST
然后我想将它们分解,例如:
我的 id-s 是 38 和 310。我在我的 html 文件中将 id-s 设置为这个 id = "38.310"。
$_POST
之后,我想爆炸id-s:
$id=$_POST['id'];
echo($id); // Gives 38.31
$new_id = explode(".", $id);
echo($new_id[0]); // Gives 38
echo($new_id[1]); // Gives 31
是让这些 id-s 不四舍五入的方法吗?
我需要38
和310
!ID 310
也可以1003000
...
编辑:
function dostuff(document, message, id, action) {
var eingabe;
eingabe = confirm(message);
if (eingabe === true) {
document.msgform.action.value = action;
document.msgform.id.value = id;
document.msgform.submit();
} else {
return true;
}
return false;
}
链接
<a href="#" onclick="dostuff(document, 'MESSAGE',<?php echo($row['vID']);?>.<?php echo($row['id']);?>,'FITTER_fitter_repaired');" class="button small red" >ACTION</a>
$row['vID'] = 38
$row["ID"] = 310
我的提交看起来像这样
<form enctype="multipart/form-data" name="msgform" action="" method="post">
<input type="hidden" value="" name="action"/>
<input type="hidden" value="" name="id"/>
</form>
不是 100% 确定为什么要这样做,但为什么不只使用 POST 数组,例如
id[]=38&id[]=310
是不是让这些 ID 不四舍五入的方法?
有几种方法,我更喜欢将其转换为整数:
$id = (int)$_POST['id'];
其他方式将是intval()
或floor()
。
我不知道
dostuff
函数在做什么,但Javascript是邪恶的。在值两边加上引号。这样就不涉及转换,它被发布为字符串。
<a href="#"
onclick="dostuff(document, 'MESSAGE', '<?php echo($row['vID']);?>.<?php echo($row['id']);?>','FITTER_fitter_repaired');" class="button small red" >ACTION</a>
^ ^
编辑:
但我也认为李的解决方案会更好。只需制作 2 个输入字段并将它们填写到您的 dostuff
函数中即可。您还可以为输入字段提供 id,以便于填写。
<input id="id1" type="hidden" value="" name="id[]"/>
<input id="id2" type="hidden" value="" name="id[]"/>
或者,如果你不明白@Lee答案,你可以使用.
以外的其他东西作为分隔符,这样PHP就不会假设变量是一个数字。最好不要使用昏迷,因为在某些国家/地区,这是小数点。
例如,使用美元符号 'id="38$310">
和$new_id = explode("$", $id);