【问题标题】:1 checkbox with 2 value from sql pass the selection来自 sql 的 1 个具有 2 个值的复选框通过选择
【发布时间】:2011-05-20 23:25:18
【问题描述】:

大家好 现在是 2 周,我正在寻找我的问题的答案,但没有运气。希望有人能帮我解决这个问题

我有一个从数据库调用的复选框选项

<form style="margin-top:-30px" method="POST" action="extradata.php">
<?php
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > $i) {
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");

print "<input type='checkbox' name='extra[]' value='$NA'></td>";
$i++;
}
?>

我想要做的是将值传递给extradata.php 2 值
1.$NA,
2.$PR
选择框后,然后插入数据库 $NA to ex_tra和 $PR to ex_price

>

extradata.php

<?php
require_once 'library/config.php';

$id=$_POST['pd_id'];
$ssid=$_POST['ct_session_id'];
$total=$_POST['tot'];
$name=$_POST['basedes'];
$qty=$_POST['ct_qty'];
$extra_array = $_POST['extra'];
if ( $extra_array > "0" ) {
foreach ($extra_array as $one_extra) {
$source .= $one_extra.", "; }
$extra = substr($source, 0, -2);
} else {}
$result=mysql_query("INSERT INTO tbl_cart (pd_id, ct_qty, ct_session_id, ex_tra, ex_tra2, ex_price, ct_date) VALUES ('$id','$qty','$ssid','$extra','$name','$total', NOW())");

?>

最好的尊重

【问题讨论】:

  • 您在提交问题时是否看过预览?

标签: php sql checkbox


【解决方案1】:

在一个变量中发送两个值必然会变得混乱。我只需发送 id 并在 extradata.php 中再次从数据库中获取相应的值。

如果你真的想发送多个值,我会为复选框使用固定索引(不是extra[],而是extra[SOME_NUMBER],并在它旁边添加一个隐藏字段(extra_pr[SOME_NUMBER]?)来传递第二个值。

请注意,您必须使用固定索引,因为未选中的复选框不会被发布,但所有隐藏字段都会被发布。

【讨论】:

  • 谢谢你最后我找到了一个解决方案 print "";这给了我所有的价值,包括总价然后我在 extradata.php $vowels = array("1", "2", "3", "4", "5", "6", "7", “8”、“9”、“0”、“₪”、“+”、“.”); $string = str_replace($vowels, '', $extra);要删除价格和 vwala,我会得到一张带有产品名称的表格和一张带有价格的表格
  • @gabby 这是一个解决方案,但就像我说的那样,这肯定会变得混乱,在这种情况下,当名称包含数字时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-17
  • 1970-01-01
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
相关资源
最近更新 更多