Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > อยากทราบการคำนวณส่วนลดเป็นเปอร์เซ็นต์ แบบใส่ตัวเลขอิสระ ใน php +mysql ครับ



 

อยากทราบการคำนวณส่วนลดเป็นเปอร์เซ็นต์ แบบใส่ตัวเลขอิสระ ใน php +mysql ครับ

 



Topic : 131424



โพสกระทู้ ( 59 )
บทความ ( 0 )



สถานะออฟไลน์




phppercent



<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="0">
<table width="778" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<?php require_once('head.php'); ?>

<?

//============ Check ว่ามีซ้ำแล้วหรือยัง
if($_GET["ProductID"] != "")
{
for($i=0;$i<=count($_SESSION["strProductID"]);$i++)
{
if($_SESSION["strProductID"][$i] == $_GET["ProductID"])
{
header("location:$_SERVER[PHP_SELF]");
exit();
}
}
}

//============ ถ้ามีการเลือกรายการสินค้าให้เก็บลง Session
if(trim($_GET["ProductID"]) != "")
{
$_SESSION["strP"]=$_SESSION["strP"]+1;
$_SESSION["strProductID"][$_SESSION[strP]]=$_GET["ProductID"];
$_SESSION["strQuanlity"][$_SESSION[strP]]=1;
session_write_close();
header("location:$_SERVER[PHP_SELF]");
}

//============ กรณีลบรายการสั่งซื้อ
if(trim($_GET["action"]) == "Del")
{
$_SESSION["strProductID"][$_GET[P]]="";
$_SESSION["strQuanlity"][$_GET[P]]="";
session_write_close();
header("location:$_SERVER[PHP_SELF]");
}

//============ กรณีการแก้ไขรายการสั่งซื้อ
if(trim($_POST["action"]) == "Update")
{
for($i=0;$i<count($_POST["txtQua"]);$i++)
{
$strP=$_POST[txtP][$i];
$strQ=$_POST["txtQua"][$i];
if($strQ <= 0)
{
$strQ=1;
}

$_SESSION["strQuanlity"][$strP]=$strQ;
/*
$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"][$strP]."'");
if($result["Stock"] < $strQ)
{
$_SESSION["strQuanlity"][$strP]=$result["Stock"];
echo"<script language='JavaScript'>";
echo"alert('รหัสสินค้า [ $result[ProductCode] ] มีจำนวน Stock ไม่เพียงพอ');";
echo"</script>";
}
*/

}
session_write_close();
//============ กระโดด Refresh ใหม่อีกรอบ
header("location:$_SERVER[PHP_SELF]");
}
?>
</td>
</tr>
<tr>
<td><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#f2f2f6" bgcolor="#FFFFFF">
<tr>

<td width="54%" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="417" height="310" valign="top">
<form action="" method="post" name="frmCart" id="frmCart">
<table width="750" border="0">
<tr>
<td><table width="418" height="22" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
<td width="8"> <img src="image/menu01.jpg" width="8" height="22" alt=""></td>
<td width="389" background="image/menu02.jpg"><div align="center"><strong>สร้างใบเสนอราคา
<input name="action" type="hidden" id="action" value="Update">
</strong></div></td>
<td width="9"> <img src="image/menu03.jpg" width="9" height="22" alt=""></td>
</tr>
</table>
<strong> </strong></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><table width="98%" height="21" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<tr bgcolor="#FFFFFF">
<td><div align="center">No.</div></td>
<td>Item No.</td>
<td>Description</td>
<td><div align="center">Product Picture</div></td>
<td><div align="center">Qty</div></td>
<td><div align="center">Unit</div></td>
<td><div align="center">Price List</div></td>
<td>Discount</td>
<td><div align="center">Prics/Unit</div></td>
<td><div align="center">Total</div></td>
</tr>
<?

//============ ทำการแสงรายการที่ได้เลือกว่ามีกี่รายการ

$strNum=0;
$strTotal=0;
for($i=0;$i<=count($_SESSION["strProductID"]);$i++)
{
//============ เลือกว่ารายการสินค้าใดบ้าง
$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"]["$i"]."' ");
if($result)
{
$strNum++;
?>
<tr bgcolor="#FFFFFF">
<td width="9%"> <div align="center">
<?=$strNum;?>
<a href="javascript:if(confirm('ลบรายการสินค้า')==true){window.location='<?=$_SERVER['PHP_SELF'];?>?action=Del&P=<?=$i;?>';}"><img src="image/deleteC.gif" width="12" height="11" border="0"></a></div></td>
<td width="10%">
<?=$result["ProductCode"];?>
</td>
<td width="25%">
<?=$result["ProductName"];?>
</td>
<td width="14%"> <div align="right">
<img src="../picture/<?=$result["Picture"];?>"width="50" height="50"></td>
<td width="13%"><div align="center">
<input name="txtP[]" type="hidden" id="txtP[]" value="<?=$i;?>">
<input name="txtQua[]" type="text" id="txtQua<?=$strNum;?>" style="width:30px;text-align:right" value="<?=$_SESSION["strQuanlity"]["$i"];?>" maxlength="3" onChange="checknum(this.value,'txtQua<?=$strNum;?>');">
</div></td>
<td width="8%">
<?=$result["Unit"];?>
</td>
<td width="13%"><?="".number_format($result["Price"], 2,'.',',');?></td>

<td width="13%">

<div align="center">
<input name="txtP[]" type="hidden" id="txtP[]" value="<?=$iper;?>">
<input name="txtQua[]" type="text" id="txtQua<?=$strNum;?>" style="width:30px;text-align:right" value="<?=$_SESSION["strQuanlity2"]["$iper"];?>" maxlength="3" onChange="checknum(this.value,'txtQua<?=$strNum;?>');">

%</div></td>
<td width="10%"> <div align="right">
<?="".number_format(($result["Price"]+$result[""])*$_SESSION["strQuanlity2"]["$iper"], 2,'.',',');?>
</div></td>

<td width="16%"> <div align="right">
<?="".number_format(($result["Price"]+$result["PriceSend"])*$_SESSION["strQuanlity"]["$i"], 2,'.',',');?>
</div></td>
</tr>
<?
$strTotal=$strTotal+(($result["Price"]+$result["PriceSend"])*$_SESSION["strQuanlity"]["$i"]);
}
}
?>
</table>
<br> <table width="98%" height="21" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<tr bgcolor="#FFFFFF">
<td><div align="right">จำนวน (รายการ)</div></td>
<td> <div align="right">
<?=$strNum;?>
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> <div align="right">ราคารวม (บาท)</div></td>
<td width="16%"> <div align="right">
<?="".number_format($strTotal, 2,'.',',');?>
</div></td>
</tr>
</table></td>
</tr>
<tr>
<td width="378"><div align="center"><br>
<?
if($strNum==0)
{
echo "<br><center><strong><font color=red>ไม่มีรายการสั่งซื้อ</font></strong></center><br><br>";
}
?>
<input name="BtnContinute" type="button" class="button" id="BtnContinute2" value="ซื้อสินค้าต่อ" onClick="window.location='index.php';">
&nbsp;
<?
if($strNum>0)
{?>
<input name="BtnCalu" type="submit" class="button" id="BtnCalu" value="คำนวณเงินใหม่">
&nbsp;
<input name="BtnPayment" type="button" class="button" id="BtnPayment" value="ชำระเงิน" onClick="window.location='pay.php';">
<?}?>
<br>
</div></td>
</tr>
</table>
<p class="style59">&nbsp;</p>
</form>
<p class="style59">&nbsp;
<script language="JavaScript">
function checknum(value,fields)
{
if(!check_number(value))
{
eval("document.all."+fields+".value='1';");
alert('กรอกจำนวนไม่ถูกต้อง');
}
}

function check_number(ch){
var len, digit;
if(ch == " "){
return false;
len=0;
}else{
len = ch.length;
}
for(var i=0 ; i<len ; i++)
{
digit = ch.charat(i)
if(digit >="0" && digit <="9"){
;
}else{
return false;
}
}
return true;
}
</script></p>
<p class="style59">&nbsp;</p>
<p class="style59">&nbsp;</p></td>
</tr>
</table></td>

</tr>
<tr>
<td colspan="3" valign="top">
<?php require_once('down.php'); ?>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-07-04 16:47:20 By : TumGrape View : 952 Reply : 2
 

 

No. 1



โพสกระทู้ ( 421 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

อาจจะไม่ได้ช่วยแก้ไข code นะครับ
แต่มีวิธีการคำนวนมาให้ดูครับ
Code (PHP)
<meta charset="utf-8">
<?php
    $price_product = 1500; //$result['price']; ราคาสินค้าต่อหน่วย
    $qty = 15; //$_POST['qty'];จำนวนสินค้าที่รับเข้า
    $discount = 10; //$_POST['valuenamber'];รับเข้าเปอเซ็นส่วนลด
    //หาผลรวมสินค้า
    $sum_price = $price_product * $qty;

    $percent_price = ($sum_price * $discount) /100;
    $sum_priceorder = $sum_price - $percent_price;
    echo "ราคาสินค้าต่อหน่วย = ".$price_product."<br>";
    echo "จำนวนสินค้า = ".$qty."<br>";
    echo "ราคารวมสินค้า = ".$sum_price."<br>";
    echo "ส่วนลด = ".$discount."%"."<br>";
    echo "เป็นเงิน = ".$percent_price."<br>";
    echo "ราคาสุทธิ = ".$sum_priceorder;
?>









ประวัติการแก้ไข
2018-07-05 09:18:48
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-07-05 09:18:02 By : nobetaking
 


 

No. 2



โพสกระทู้ ( 59 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ แมวหลังเขา มากครับ ผมจะนำไปปรับเปลี่ยนดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-07-06 09:43:33 By : TumGrape
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบการคำนวณส่วนลดเป็นเปอร์เซ็นต์ แบบใส่ตัวเลขอิสระ ใน php +mysql ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่