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,028

HOME > PHP > PHP Forum > รบกวนช่วยหน่อยค่ะคือหนูอยากจะ รวมจำนวนของสินค้าที่ลูกค้าสั่งจากทางร้าน ตามวันที่เรา select จากฐานข้อมูลค่ะ



 

รบกวนช่วยหน่อยค่ะคือหนูอยากจะ รวมจำนวนของสินค้าที่ลูกค้าสั่งจากทางร้าน ตามวันที่เรา select จากฐานข้อมูลค่ะ

 



Topic : 129798



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



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




รบกวนช่วยหน่อยนะค่ะพี่ๆ คือหนูอยากจะ รวมจำนวนของสินค้าที่ลูกค้าสั่งจากทางร้าน ตามวันที่เรา select จากฐานข้อมูลรบกวนช่วยด้วยนะคะพี่ๆ

ีีีuuuu

Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Customer Search</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
  <table width="800" border="1" color="#">
    <tr>
      <th>From Date 
      <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">To Date
	  <input name="txtKeyword2" type="text" id="txtKeyword2" value="<?php echo $_GET["txtKeyword2"];?>">Company
	  <input name="txtKeyword3" type="text" id="txtKeyword3" value="<?php echo $_GET["txtKeyword3"];?>">
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>
<?php
if($_GET["txtKeyword"] != "" or $_GET["txtKeyword2"] != "" or $_GET["txtKeyword3"] != "") 
	{
	$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database");
	$objDB = mysql_select_db("customer");
	// Search By Name or Email
	$strSQL = "SELECT * FROM cus WHERE (Date between '".$_GET["txtKeyword"]."' and '".$_GET["txtKeyword2"]."' and Company LIKE '%".$_GET["txtKeyword3"]."%')";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	?>
	<table width="800" border="1">
	  <tr>
		<th width="91" align="center">Id </th>
		<th width="91" align="center">Company </th>
		<th width="91" align="center">Code </th>
		<th width="91" align="center">Name_save </th> 
		<th width="91" align="center">Name_pro </th>
		<th width="91" align="center">Piece </th>
		<th width="91" align="center">Date </th>
		
	  </tr>
	<?php
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
	  <tr>
		<td align="center"><?php echo $objResult["Id"];?></td>
		<td align="center"><?php echo $objResult["Company"];?></td>
		<td align="center"><?php echo $objResult["Code"];?></td>
		<td align="center"><?php echo $objResult["Name_save"];?></td>
		<td align="center"><?php echo $objResult["Name_pro"];?></td>
		<td align="center"><?php echo $objResult["Piece"];?></td>
		<td align="center"><?php echo $objResult["Date"];?></td>
		</tr>
	<?php
	}
	?>
	</table>
	<table width="800" border="1">
	<tr>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91" align="center">จำนวนชิ้น</th>
		<th width="91" align="center"><?PHP 
		$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database");
		$objDB = mysql_select_db("customer");
		$SQL="SELECT SUM(Piece) AS SUMPiece FROM customer WHERE Id ='".$_GET["Id"]."'";
		?></th>
		<th width="91">&nbsp;</th>
	  </tr>
	</table>
	<?php
	mysql_close($objConnect);
}
?>




Tag : PHP, MySQL









ประวัติการแก้ไข
2017-12-26 10:34:53
2017-12-29 20:44:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-12-26 10:31:17 By : panthipa View : 969 Reply : 6
 

 

No. 1



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

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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

ใช้ sum แล้ว group by ครับ
Code (SQL)
select sum(Price) as Price, Company,  Date from table_name group by Company, Date









ประวัติการแก้ไข
2017-12-26 10:59:27
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-26 10:58:09 By : mangkunzo
 


 

No. 2



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



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


พี่หนูผิดตรงไหนชี้แนะหน่อยคะ ไม่มี error

Code
<?PHP
$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
$SQL=("select sum(Price) as Price, Company, Date from cus group by Company, Date");
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");

?>
<table width="800" border="1">
<tr>
<th width="91">&nbsp;</th>
<th width="91">&nbsp;</th>
<th width="91">&nbsp;</th>
<th width="91">&nbsp;</th>
<th width="91" align="center">จำนวนชิ้น</th>
<th width="91" align="center"><?php echo $objQuery['sum(Price)']; ?></th>
<th width="91">&nbsp;</th>
</tr>
</table>



ประวัติการแก้ไข
2017-12-26 11:34:58
2017-12-26 11:35:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-26 11:34:25 By : panthipa
 

 

No. 3



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



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

echo ตัวนี้ Price
เพราะ sum(Price) as Price
---------
No!!! <?php echo $objQuery['sum(Price)']; ?>
-----
<?php echo $objQuery["Price"]; ?>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-26 13:28:13 By : Hararock
 


 

No. 4



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



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


ลองเอาไปรวมกับโค้ดด้านบน ยังไม่คำนวณให้อยู่ดีค่ะไม่มีอะไรออกมากเลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-28 20:25:10 By : panthipa
 


 

No. 6



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



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


จขกท. หมายถึง Quantity ของสินค้าหรือเปล่าครับ เลยใช้คำว่า Piece ในการตั้งชื่อฟิลด์ ซึ่งท่านที่มาตอบเลยเข้าใจว่าเป็น

ราคาของสินค้า ( Price ) และเข้าใจว่าต้องการจำนวนราคาของแต่ละวันรวมกันเป็นวันๆไป

แต่เจตนารมย์ของ จขกท. ต้องการเพียงค่าจำนวนรวมสินค้าในระหว่างวันที่ที่กำหนด

ก็เพียงแค่ Loop บวกค่าจับใส่ตัวแปรก็น่าจะได้แล้วครับ


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Customer Search</title>
</head>
<body>
<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
  <table width="800" border="1" color="#">
    <tr>
      <th>From Date 
      <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">To Date
	  <input name="txtKeyword2" type="text" id="txtKeyword2" value="<?php echo $_GET["txtKeyword2"];?>">Company
	  <input name="txtKeyword3" type="text" id="txtKeyword3" value="<?php echo $_GET["txtKeyword3"];?>">
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>
<?php
if($_GET["txtKeyword"] != "" or $_GET["txtKeyword2"] != "" or $_GET["txtKeyword3"] != "") 
	{
	$objConnect = mysql_connect("localhost","root","03112530") or die("Error Connect to Database");
	$objDB = mysql_select_db("customer");
	// Search By Name or Email
	$strSQL = "SELECT * FROM cus WHERE (Date between '".$_GET["txtKeyword"]."' and '".$_GET["txtKeyword2"]."' and Company LIKE '%".$_GET["txtKeyword3"]."%')";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	?>
	<table width="800" border="1">
	  <tr>
		<th width="91" align="center">Id </th>
		<th width="91" align="center">Company </th>
		<th width="91" align="center">Code </th>
		<th width="91" align="center">Name_save </th> 
		<th width="91" align="center">Name_pro </th>
		<th width="91" align="center">Piece </th>
		<th width="91" align="center">Date </th>
		
	  </tr>
	<?php
        $totalQty = 0;
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
	  <tr>
		<td align="center"><?php echo $objResult["Id"];?></td>
		<td align="center"><?php echo $objResult["Company"];?></td>
		<td align="center"><?php echo $objResult["Code"];?></td>
		<td align="center"><?php echo $objResult["Name_save"];?></td>
		<td align="center"><?php echo $objResult["Name_pro"];?></td>
		<td align="center"><?php echo $objResult["Piece"];?></td>
		<td align="center"><?php echo $objResult["Date"];?></td>
		</tr>
	<?php
       $totalQty += $objResult["Piece"];
	}
	?>
	</table>
	<table width="800" border="1">
	<tr>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91">&nbsp;</th>
		<th width="91" align="center">จำนวนชิ้น</th>
		<th width="91" align="center"><?php echo $totalQty; ?></th>
		<th width="91">&nbsp;</th>
	  </tr>
	</table>
	<?php
	mysql_close($objConnect);
}
?>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-28 21:32:02 By : tomrambo
 


 

No. 7



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



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


แบบนี้ละค่ะพี่ที่หนูจะให้โชว์ ขอบคุณมากค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-29 15:54:41 By : panthipa
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนช่วยหน่อยค่ะคือหนูอยากจะ รวมจำนวนของสินค้าที่ลูกค้าสั่งจากทางร้าน ตามวันที่เรา select จากฐานข้อมูลค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่