 |
รับค่าจากแบบฟอร์มเป็นเลข 2 หรือ 3 หลัก ส่งค่าไปคำนวนได้มาแค่หลักแรก หาสาเหตุไม่เจอมีใครพอให้คำแนะนำได้บ้างไหม๊คะ |
|
 |
|
|
 |
 |
|
ขอดูโค้ดที่ใช้คำนวน
|
 |
 |
 |
 |
Date :
2013-10-23 12:14:41 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในส่วน Display (ตัวแปร $discountที่มีปัญหา)
foreach($_SESSION['cal_product'] as $p_id=>$rs) //นำสินค้าที่เลือกมาเก็บไว้ใน Table
{
//การณีที่มีการ Add สินค้ามาทีหลัง และ Id ไม่ตรงกับ ในตะกร้า
$sql="select * from productssuppliers p
inner join products a on p.ProductID=a.ProductID
inner join units b on a.UnitID =b.Unit_id
inner join category c on a.CategoryID=c.CategoryID
where p.ProductID='$p_id'";
}
$querys=mysql_query($sql) or die ("Error Query [".$sql."]");
$row=mysql_fetch_array($querys);
//echo "rs 1 :".$rs[1]."<br>";
$unt=$rs[2];
$discount =number_format($rs[3]);
Code ที่ใช้คำนวน ตัวแปร Discount ที่มีปัญหา ณ ตอนนี้ รับค่ามาจาก Array อีกที ตามโค๊ดด้านล่าง
foreach ($_SESSION['cart'] as $p_id )
{
//var_dump($p_id);
$sql="select * from productssuppliers p
inner join products a on p.ProductID = a.ProductID
inner join units b on a.UnitID = b.Unit_id
inner join category c on a.CategoryID = c.CategoryID
where p.ProductID = '$p_id'";
$query = mysql_query($sql);
$row = mysql_fetch_array($query);
$cal_Proid = $row['0'];
$_SESSION['qty'][$cal_Proid]=$_POST['Amount'][$p_id];
$_SESSION['unit'][$cal_Proid]=$_POST['Unit_p'][$p_id];
$_SESSION['discount'][$cal_Proid]=$_POST['Distcount_p'][$p_id];
$_SESSION['cal_product'][$p_id] =array($cal_Proid,$_SESSION['qty'][$cal_Proid],$_SESSION['unit'][$cal_Proid],$_SESSION['discount'][$cal_Proid]);
}
|
 |
 |
 |
 |
Date :
2013-10-23 12:28:56 |
By :
Minie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวเลขที่ว่าเนี่ย เป็นแบบนี้หรือเปล่า
1,200
2,230
ถ้าเป็นลักษณะนี้ ตัวเลขจะใช้ได้เฉพาะ หลักที่อยู่ก่อนคอมม่าครับ
เพราะฉะนั้นห้ามกรอกคอมม่าเพื่อระบุหลักพันครับ
|
 |
 |
 |
 |
Date :
2013-10-23 12:50:04 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแล้วผลลัพท์เหมือนเดิมเลยค่ะ
ค่าที่ Input ก็เป็น 15 ,50 ,10 ประมาณนี้เองนะคะ
|
 |
 |
 |
 |
Date :
2013-10-23 12:59:17 |
By :
muicom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ต้นทางคะ
$_SESSION['discount'][$cal_Proid]=$_POST['Distcount_p'][$p_id];
var_dump ค่าออกมาดู มันส่งมาแค่ค่าเดียวจิงๆค่ะ เป็นจากต้นทาง แต่ไม่ทราบสาเหตุ TT
Input Box size กับ Maxlength ก็ไม่น่าจะเกี่ยว
<input name="Distcount_p[<?=$p_id;?>]" type="text" id="Distcount_p[<?=$p_id;?>]" value="<?=$rs[3];?>" size="10" maxlength="10"/>
|
 |
 |
 |
 |
Date :
2013-10-23 13:06:49 |
By :
muicom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<input type="text" name="discount" value="15,10,20" />
<?php
if(isset($_POST["discount"]) && $_POST["discount"] !== ''){
if(strstr($_POST["discount"] , ','))
$discountAmount = explode("," , $_POST["discount"]);
else $discountAmount = $_POST["discount"];
if(is_array($discountAmount))
print_r($discountAmount);
else
echo $discountAmount;
}
?>
ลองดูครับ
|
 |
 |
 |
 |
Date :
2013-10-23 14:04:33 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|