จะแสดงผลรวมต้องใส่ยังไงเหรอคะ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา จะแสดงผลรวมต้องใส่ยังไงเหรอคะ

จะแสดงผลรวมต้องใส่ยังไงเหรอคะ

คือต้องการแสดงค่าให้ออกมาตามรูปค่ะ

ลักษณะคือ ดึงค่าออกมาจาก db ซึ่งค่าที่ดึงออกมาจะเป็นแถวที่นำหน้าด้วยคำว่า (Order ID : TW........) ตามตัวอย่างบรรทัดที่ 1 และ 3

ส่วนบรรทัดที่ 2และ4 เป็นการคำนวนคอมมิชชั่น ซึ่งคิดจาก Credit IN แล้วเอาคำนวณแบบเปอร์เซ็น

ซึ่งตรงส่วนคิดเป็นเปอร์เซ็นต์ทำได้แล้วค่ะ แต่ติดตรง Balance ซึ่งเป็นยอดรวมค่ะ  จะให้แสดงค่าออกมาต้องทำยังไงเหรอคะ เพราะมันต้องคิดค่าจากบรรทัดก่อน

เช่น รับเงินเข้ามา 100 balance=100

เสียค่า commission (Credit Out) = 30%  balance=70

รับเงินเพิ่ม 999 balance=1069

เสียค่า commission (Credit Out) = 25%  balance=819.25

จะให้โชว์ค่า balance ต้องเขียนยังไงเหรอคะ

code ที่เป็นทำแบบนี้ค่ะ

$sql = "SELECT cart.*,bill.* FROM cart,bill WHERE cart.order_id = bill.order_id AND  cart.member_id='$_SESSION[member_id]' ORDER BY cart.eventdate ASC";
$recordSet=$conn->Execute($sql);
$software_id = $recordSet->fields[software_id];

$sql_software = "SELECT * FROM software ";
$sql_software .= " WHERE software_id='$software_id' and statusR ='Y'";

$recordSoftware = $conn->Execute[$sql_software];
$license_type = $recordSoftware->fields[$software_license_type];

function commission($price){
	if($price<=500){
		$result=$price*0.3;	
	}
	else if($price>500 and $price<=1000){
		$result=$price*0.25;
	}
	else if($price>1000 and $price<=5000){
		$result=$price*0.2;
	}
	else if($price>5000 and $price<=10000){
		$result=$price*0.15;
	}
	else{
		$result=$price*0.1;
	}
	return $result;
}
function chk_commission($price){
	if($price<=500){
		$result=30;	
	}
	else if($price>500 and $price<=1000){
		$result=25;
	}
	else if($price>1000 and $price<=5000){
		$result=20;
	}
	else if($price>5000 and $price<=10000){
		$result=15;
	}
	else{
		$result=10;
	}
	return $result;
}

	<table width="100%" border="1">
	  <tr>
		<td>Date</td>
		<td>ID</td>
		<td>Detail</td>
		<td>Credit Out(Baht)</td>
		<td>Credit In(Baht)</td>
		<td>Balance(Baht)</td>
	  </tr>
<? 
while (!$recordSet->EOF)
{
?>
	  <tr>
		<td><?=$recordSet->fields[eventdate]?></td>
		<td><?=$recordSet->fields[cart_id]?></td>
		<td><?=$recordSoftware->fields[software_name]." (Order ID : ".$recordSet->fields[order_id].")" ?></td>
		<td>&nbsp;</td>
		<td><?=$recordSet->fields[price]?></td>
		<td>// ใส่ balance ยังไง</td>
	  </tr>
      <? $commission=$recordSet->fields[price]; ?>
	  <tr>
		<td><?=$recordSet->fields[eventdate]?></td>
		<td><?=$recordSet->fields[cart_id]?></td>
		<td><?="Commission Free - ".chk_commission($commission)."% (Order ID : ".$recordSet->fields[order_id].")"?></td>
		<td>
		<? 
		echo commission($commission);
		?>
        </td>
		<td>&nbsp;</td>
		<td>// ใส่ balance ยังไง</td>
	  </tr>
<?
	$recordSet->MoveNext();
}
?>
	</table>


Atomy 58.8.27.xxx 01-03-2011 17:53:29

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1

ลองสร้างตัวแปรเก็บค่า ตามตัวอย่างดู
 

<?php
$sql = "SELECT cart.*,bill.* FROM cart,bill WHERE cart.order_id = bill.order_id AND  cart.member_id='$_SESSION[member_id]' ORDER BY cart.eventdate ASC";
$recordSet=$conn->Execute($sql);
$software_id = $recordSet->fields[software_id];

$sql_software = "SELECT * FROM software ";
$sql_software .= " WHERE software_id='$software_id' and statusR ='Y'";

$recordSoftware = $conn->Execute[$sql_software];
$license_type = $recordSoftware->fields[$software_license_type];

function commission($price){
	if($price<=500){
		$result=$price*0.3;	
	}
	else if($price>500 and $price<=1000){
		$result=$price*0.25;
	}
	else if($price>1000 and $price<=5000){
		$result=$price*0.2;
	}
	else if($price>5000 and $price<=10000){
		$result=$price*0.15;
	}
	else{
		$result=$price*0.1;
	}
	return $result;
}
function chk_commission($price){
	if($price<=500){
		$result=30;	
	}
	else if($price>500 and $price<=1000){
		$result=25;
	}
	else if($price>1000 and $price<=5000){
		$result=20;
	}
	else if($price>5000 and $price<=10000){
		$result=15;
	}
	else{
		$result=10;
	}
	return $result;
}
?>
<?php
// 
$agg_balance=0;
?>
	<table width="100%" border="1">
	  <tr>
		<td>Date</td>
		<td>ID</td>
		<td>Detail</td>
		<td>Credit Out(Baht)</td>
		<td>Credit In(Baht)</td>
		<td>Balance(Baht)</td>
	  </tr>
<? 
while (!$recordSet->EOF)
{
?>
	  <tr>
		<td><?=$recordSet->fields[eventdate]?></td>
		<td><?=$recordSet->fields[cart_id]?></td>
		<td><?=$recordSoftware->fields[software_name]." (Order ID : ".$recordSet->fields[order_id].")" ?></td>
		<td>&nbsp;</td>
		<td><?=$recordSet->fields[price]?></td>
		<td>
		<?php $agg_balance+=$recordSet->fields[price]; ?>
		<?=$agg_balance?>
        </td>
	  </tr>
      <? $commission=$recordSet->fields[price]; ?>
	  <tr>
		<td><?=$recordSet->fields[eventdate]?></td>
		<td><?=$recordSet->fields[cart_id]?></td>
		<td><?="Commission Free - ".chk_commission($commission)."% (Order ID : ".$recordSet->fields[order_id].")"?></td>
		<td>
		<? 
		echo commission($commission);
		?>
        </td>
		<td>&nbsp;</td>
		<td>
        <?php $agg_balance-=commission($commission); ?>
		<?=$agg_balance?>
        </td>
	  </tr>
<?
	$recordSet->MoveNext();
}
?>
	</table>

 



Ninenik 124.120.215.xxx 02-03-2011
 ความคิดเห็นที่ 2

ได้แล้วค่ะ ขอบคุณมากๆนะคะ



Atomy 58.8.27.xxx 02-03-2011 09:56






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ