2011-05-20 115 views
0

大家好 现在是2周,我寻找我的问题的答案,没有运气。希望有人为能帮助我在此1复选框与来自sql的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++; 
} 
?> 

什么,我试图做的是与2值
1. $NA传递价值extradata.php调用chackbox选项,
2. $PR
当选择框然后插入到数据库中的$NAex_tra$PRex_price

所有

+0

提交您的问题时有什么机会看到预览? – Fosco 2011-05-20 15:13:42

回答

2

一个变量发送两个值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())"); 

?> 

最佳方面势必会导致混乱。我只需发送该ID并从extradata.php中再次获取数据库中的相应值。

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

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

+0

谢谢finaly我找到了解决方案print““;这给我所有的价值,包括总价,然后我用extraData.php $ vowels = array(“1”,“2”,“3”,“4”,“5”,“6”,“7”, “8”,“9”,“0”,“₪”,“+”,“。”); $ string = str_replace($ vowels,'',$ extra);删除价格和vwala我得到一个表与产品名称和一个与价格 – 2011-05-20 17:05:28

+0

@gabby这是一个解决方案,但就像我说的那样,这一定会变得混乱,在这种情况下,当一个名称包含数字。 – jeroen 2011-05-20 17:16:06