|
 |
|
ช่วยดูโค๊ดให้หน่อยครับ รวมเงินทั้งหมดในรายการสั่งซื้อ เป็นราคารวมอีกทีครับ |
|
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2010-11-03 09:45:50 |
By :
chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงๆแล้วการ query แบบนี่จะทำให้ช้า ลองไปอ่านเรื่อง join ดูนะครับ มีไรสงสัยถามได้ครับ
Code (PHP)
<?
$n=0;
$total_cost=0; // new line
$cmd_st= "select * from saletemp where sale_id = '$row_s[sale_id]'";
$result_st = mysql_query($cmd_st,$link);
while($row_st=mysql_fetch_array($result_st)){
$cmd_pros = "select * from productstock where pros_id = '$row_st[pros_id]'";
$result_pros = mysql_query($cmd_pros,$link);
$row_pros = mysql_fetch_array($result_pros);
$cmd_num = "select * from saletemp where pro_auto = '$row_pros[pro_auto]' and sale_id='$row_s[sale_id]' ";
$result_num = mysql_query($cmd_num,$link);
$num = mysql_num_rows($result_num);
$cmd_pro = "select * from product where pro_auto = '$row_pros[pro_auto]'";
$result_pro = mysql_query($cmd_pro,$link);
$row_pro = mysql_fetch_array($result_pro);
if($test != $row_st[pro_auto]){
$n++;
$cost=$row_pro[pro_pricesale]*$num;
$total_cost+=$cost;
if($row_s[sale_due] == $fullday) {
echo"<b><font size='2' color = 'blue'>$n : $row_pro[pro_name] <font size='1' color = 'green'>[ $num ชิ้น $cost bath ]</font><BR>";
}
else {
echo"<font size='2'> $n : $row_pro[pro_name] <font size='1' color = 'green'>[ $num ชิ้น $cost bath ]</font><BR>";
}
}
$test = $row_st[pro_auto];
}
?>
</td>
<td align="center" bgcolor="#CCCCCC">
<?
if($row_s[sale_due] == $fullday) {
echo"<b><font size='2' color = 'blue'>$total_cost</font></b>";
}
else {
echo"<font size='2'>$total_cost";
}
?>
</td>
|
ประวัติการแก้ไข 2010-11-03 09:57:32 2010-11-03 09:58:18
 |
 |
 |
 |
Date :
2010-11-03 09:55:46 |
By :
kerb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ คุณkerb เด๋วลองเลย ไว้ได้ผลยังงัยจะมาบอกน่ะครับ
จริงๆแล้วผมมือใหม่มากๆเลย โค๊ดที่ได้ก็เอามาจากรุ่นพี่ซึ่งเค้าทำยังไม่เสร็จอะครับ
|
 |
 |
 |
 |
Date :
2010-11-03 19:54:25 |
By :
chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณkerbครับ ผมทำตามแล้ว ผลลัพธ์เป็นแบบนี้[img=
ส่วนนี่คือผมลบโค๊ดออก ตัวแปรนี้อ่ะครับ$row_pro 
ช่วยดูให้หน่อยน่ะครับอีกนิดเดียวเอง
|
 |
 |
 |
 |
Date :
2010-11-03 21:21:35 |
By :
chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาโค๊ด ที่ Query ด้วย วิธีการ Join มาดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2010-11-03 22:20:22 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่คือโค๊ดปัจจุบันครับ หลังจากที่คุณ kerb ช่วยเพิ่มโค๊ดให้อ่ะครับ
อยากให้ช่วยดูให้หน่อย(ตามรูปภาพ)จะทำยังงัยให้คำนวนราคาในรายการทั้งหมดให้ถูกต้องตามจำนวนสินค้าด้วย เนื่องจากในรายการสินค้าที่2มีสินค้าสองชิ้นแต่ผลลัพธ์ออกแค่ราคาสินค้ารายการที่1กับ2บวกกันอ่าครับ
<?
$n=0;
$total_cost=0; ----------------> คุณ kerb
$cmd_st= "select * from saletemp where sale_id = '$row_s[sale_id]'";
$result_st = mysql_query($cmd_st,$link);
while($row_st=mysql_fetch_array($result_st))
{
$cmd_pros = "select * from productstock where pros_id = '$row_st[pros_id]'";
$result_pros = mysql_query($cmd_pros,$link);
$row_pros = mysql_fetch_array($result_pros);
$cmd_num = "select * from saletemp where pro_auto = '$row_pros[pro_auto]' and sale_id='$row_s[sale_id]' ";
$result_num = mysql_query($cmd_num,$link);
$num = mysql_num_rows($result_num);
$cmd_pro = "select * from product where pro_auto = '$row_pros[pro_auto]' ";
$result_pro = mysql_query($cmd_pro,$link); $row_pro = mysql_fetch_array($result_pro);
$row_pro = mysql_fetch_array($result_pro);
if($test != $row_st[pro_auto])
{
$n++;
$cost=$row_pro[pro_pricesale]*$num;
$total_cost+=$cost;----------------> คุณ kerb
if($row_s[sale_due] == $fullday)
{
echo"<b><font size='2' color = 'blue'>$n : $row_pro[pro_name] <font size='1' color = 'green'>[ $num ชิ้น $cost bath ]</font><BR>";}
else
{
echo"<font size='2'> $n : $row_pro[pro_name] <font size='1' color = 'green'>[ $num ชิ้น $cost bath ]</font><BR>";}
}
$test = $row_st[pro_auto];
}?>
</td>
<td align="center" bgcolor="#CCCCCC">
<?
if($row_s[sale_due] == $fullday)
{
echo"<b><font size='2' color = 'blue'>$total_cost</font></b>"; }
else {
echo"<font size='2'>$total_cost</font>";}?> </td>
|
 |
 |
 |
 |
Date :
2010-11-03 23:38:26 |
By :
Chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo"<b><font size='2' color = 'blue'>$n : $row_pro[pro_name] <font size='1' color = 'green'>[ $num ชิ้น $cost bath]
ดูตาม code ข้างบน น่า จะ แบบนี้ก่อนนะ
$cost1=$cost*$num; //คูณจำนวนก่อน 1 ชิ้น 2 ชิ้น
แล้วจึง รวม
$total_cost+=$cost1;
ถ้าเข้าใจผิดขออภัยครับ
|
 |
 |
 |
 |
Date :
2010-11-04 06:38:41 |
By :
p_kokmas |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รวมราคาถูกต้องแล้วครับ
ขอบคุณคุณkerbและคุณant มากๆน่ะครับ
|
 |
 |
 |
 |
Date :
2010-11-04 09:32:17 |
By :
Chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยผมอีกนิดนึงครับ
ก่อนหน้านี้ที่ยังรวมราคาไม่สมบูรณ์ จะใช้ตัวแปร $row_s[sale_cost] ซึ่งรวมราคาไม่ถูกต้องแต่ทำให้ลงฐานข้อมูลเลย
แล้วตัวแปร $total_cost นี้จะเขียนยังงัยให้ลงฐานข้อมูลครับ


|
 |
 |
 |
 |
Date :
2010-11-05 10:08:34 |
By :
Chupong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|