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 > คำนวนราคาจากสินค้าภายใต้เงื่อนไข ผมใช้ LIKE 2 field และ between ผลการบวกมันก็ถูกครับ แต่บางทีบวกผิด ช่วยดูโค๊ดไห้หน่อย



 

คำนวนราคาจากสินค้าภายใต้เงื่อนไข ผมใช้ LIKE 2 field และ between ผลการบวกมันก็ถูกครับ แต่บางทีบวกผิด ช่วยดูโค๊ดไห้หน่อย

 



Topic : 101344



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



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




อ

คำนวนราคาจากสินค้าภายใต้เงื่อนไข ผมใช้ LIKE 2 field และ between ผลการบวกมันก็ถูกครับ แต่บางทีบวกผิด ช่วยดูโค๊ดไห้หน่อย

Code (PHP)
<?	
include("../../config.inc.php") ;
$sum_rc="select sum(Price) as sum_paid from Redem  WHERE (CategoryProduct LIKE '%".$_GET["txtKeyword1"]."%' 
and  Floor LIKE '%".$_GET["txtKeyword2"]."%')";
									
if($_GET["txtKeyword3"] != "" or $_GET["txtKeyword4"] != ""){	
$objQuery .= " and (DateShoping between '".$_GET["txtKeyword3"]."' and '".$_GET["txtKeyword4"]."') ";
									
}
$query_sum=mssql_query($sum_rc);
$result = mssql_fetch_array($query_sum);
echo $result["sum_paid"];
?>




Tag : PHP, Ms SQL Server 2005







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-10-04 19:01:33 By : วันพีช View : 626 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

Quote:
$objQuery


ใช้ทำอะไรครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-05 11:03:11 By : mr.win
 


 

No. 2



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



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


มันเป็น sql ของผมตอน search นะครับ

include("../../config.inc.php") ;
[font=Verdana]$objQuery[/font] = "SELECT * FROM Redem WHERE (CategoryProduct LIKE '%".$_GET["txtKeyword1"]."%'
and Floor LIKE '%".$_GET["txtKeyword2"]."%')";
if($_GET["txtKeyword3"] != "" or $_GET["txtKeyword4"] != ""){
$objQuery .= " and (DateShoping between '".$_GET["txtKeyword3"]."' and '".$_GET["txtKeyword4"]."') ";
}


ถ้าผม search โดยกำหนด where =IDCard มันก็รวมได้ แตพอดีอยากจะหาเป็นรายเดือน โดยกำหนดช่วงเวลา

ดังนี้ครับ

<?php
session_start() ;
if(!session_is_registered("login_true_admin")) {
echo "<meta http-equiv='refresh' content='0;url=index.php'>" ;
exit() ;
}
?>
<!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=windows-874" />
<title>SEARCH FOR ADMIN</title>
<link href="../../fonts.css" rel="stylesheet" type="text/css" />
<link href="../../font.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.fontMEDIEM {
font-size: medium;
text-align: left;
}
.big {
font-size: large;
}
body {
background-color: #E9E9E9;
}
.center-head-report {
}
.fontMEDIEM1 { font-size: medium;
}
-->
</style>

</head>
<!-- Start Datepick -->
<link type="text/css" href="../../date/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="../../date/jquery.datepick.js"></script>
<script type="text/javascript">
$(function() {
$('#txtKeyword3').datepick();
$('#txtKeyword4').datepick();

$('#inlineDatepicker').datepick({onSelect: showDate});
});

function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
<!-- Start Datepick -->
</head>
<title>&lt;&lt;..SEARCH FOR ADMIN..&gt;&gt;</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<body>
<form name="frmSearch" method="get" action="<?=$_SERVER['../SCRIPT_NAME'];?>">
<table width="950" border="0" align="center">
<tr>
<td bgcolor="#666666"><table width="80%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr>
<th colspan="2" align="center" bgcolor="#9F9F9F" class="font"><strong class="new"><br />
REPORT ยอดซื้อสินค้า<br />
<br />
</strong></th>
</tr>
<tr>
<th align="center" bgcolor="#9F9F9F" class="fonts"><strong>ประเภทสินค้า</strong></th>
<th align="left" bgcolor="#E9E9E9" class="fonts"><span class="fontMEDIEM">
<select name="txtKeyword1" size="1" id="txtKeyword1" value="<?=$_GET["txtKeyword1"];?>">
<option value="" selected="selected"></option>
<option value="คอมพิวเตอร์และเน็ตเวิร์ค">คอมพิวเตอร์และเน็ตเวิร์ค</option>
<option value="เครื่องเสียง/เครื่องไฟฟ้า">เครื่องเสียง/เครื่องไฟฟ้า</option>
<option value="กล้องดิจิตอล">กล้องดิจิตอล</option>
<option value="ไอทีแบรนด์">ไอทีแบรนด์</option>
<option value="ศูนย์บริการด้านไอที">ศูนย์บริการด้านไอที</option>
<option value="มือถือ">มือถือ</option>
<option value="ธนาคาร">ธนาคาร</option>
<option value="บริการทางธุรกิจ">บริการทางธุรกิจ</option>
<option value="สถาบันการศึกษา">สถาบันการศึกษา</option>
<option value="เครื่องประดับ">เครื่องประดับ</option>
<option value="สุขภาพและความงาม">สุขภาพและความงาม</option>
<option value="งานอดิเรกและของเล่น">งานอดิเรกและของเล่น</option>
<option value="ฟู้ด อเวนิว">ฟู้ด อเวนิว</option>
<option value="ภัตตาคาร">ภัตตาคาร</option>
<option value="อาหารจานด่วน">อาหารจานด่วน</option>
</select>
</span></th>
</tr>
<tr>
<th width="95" align="center" bgcolor="#9F9F9F" class="fonts"><strong>ชั้น</strong></th>
<th align="left" bgcolor="#E9E9E9" class="fonts"><span class="fontMEDIEM1">
<input name="txtKeyword2" type="text" id="txtKeyword2" value="<?=$_GET["txtKeyword2"];?>" />
</span></th>
</tr>
<tr>
<th align="center" bgcolor="#9F9F9F" class="big"><span class="fontMEDIEM"><span class="fonts"><strong>วันซื้อสินค้า</strong></span></span></th>
<td bgcolor="#E9E9E9" class="fonts"><span class="font">
<input name="txtKeyword3" type="text" id="txtKeyword3" value="<?=$_GET["txtKeyword3"];?>" />
<img src="../../date/calendar-blue.gif" width="16" height="15" /> </span>ถึง<span class="font">
<input name="txtKeyword4" type="text" id="txtKeyword4" value="<?=$_GET["txtKeyword4"];?>" />
<img src="../../date/calendar-blue.gif" width="16" height="15" /> </span></td>
</tr>
<tr>
<th align="left" bgcolor="#9F9F9F">&nbsp;</th>
<th align="left" bgcolor="#E9E9E9"><label>
<!-- <input type="submit" name="button" id="button" value="Submit" /> -->
<input type="image" name="imageField" id="imageField" src="../../image/search.png">
&nbsp;&nbsp; </label>
<a href="report_month.php"><img src="../../image/clear.png" width="82" height="31" border="0" /></a></th>
</tr>
</table></td>
</tr>
</table>
</form>
<?
// start code
include("../../config.inc.php") ;
$objQuery = "SELECT * FROM Redem WHERE (CategoryProduct LIKE '%".$_GET["txtKeyword1"]."%'
and Floor LIKE '%".$_GET["txtKeyword2"]."%')";
if($_GET["txtKeyword3"] != "" or $_GET["txtKeyword4"] != ""){
$objQuery .= " and (DateShoping between '".$_GET["txtKeyword3"]."' and '".$_GET["txtKeyword4"]."') ";
}

/* code <>
$objQuery = "SELECT * FROM Member WHERE (IDCard LIKE '%".$_GET["txtKeyword"]."%'
DateOfBrd >= '$txtKeyword2' and DateOfBrd <= '$txtKeyword')";
*/
$objQuery = mssql_query($objQuery) or die ("Error Query [".$objQuery."]");
$Num_Rows = mssql_num_rows($objQuery);

$Per_Page =10; // Per Page

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows)
{
$Page_End = $Num_Rows;
}

?>
<table width="950" border="0" align="center" cellpadding="5" cellspacing="2">
<tr bgcolor="#E9E9E9">
<td height="97" bgcolor="#666666"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="2">
<tr class="center-head-report">
<th colspan="7" align="right" bgcolor="#C0C0C0" class="fonts"><a href="report_month_search.php?txtKeyword1=<?=$_GET["txtKeyword1"];?>&amp;txtKeyword2=<?=$_GET["txtKeyword2"];?>&amp;txtKeyword3=<?=$_GET["txtKeyword3"];?>&amp;txtKeyword4=<?=$_GET["txtKeyword4"];?>"><img src="../../image/doc_excel_table.png" width="16" height="16" border="0" /></a>&nbsp;<img src="../../image/doc_pdf.png" width="16" height="16" border="0" /></th>
</tr>
<tr class="center-head-report">
<th width="116" align="center" bgcolor="#C0C0C0" class="fonts">บัตรประชาชน</th>
<th width="146" align="center" bgcolor="#C0C0C0"> <div align="center" class="fonts">ชื่อร้านค้า</div></th>
<th width="64" bgcolor="#C0C0C0" class="fonts">ชั้น</th>
<th width="199" bgcolor="#C0C0C0" class="fonts"><div align="center" class="fonts">ประเภทร้านค้า </div></th>
<th width="141" bgcolor="#C0C0C0" class="fonts">วันที่</th>
<th width="119" bgcolor="#C0C0C0" class="fonts">ราคา</th>
<th width="65" bgcolor="#C0C0C0" class="fonts">รวม</th>
</tr>
<?
for($i=$Page_Start;$i<$Page_End;$i++)
{
?>
<tr>
<td align="center" bgcolor="#E9E9E9" class="fonts"><?=mssql_result($objQuery,$i,"IDCard");?></td>
<td align="center" bgcolor="#E9E9E9"><span class="fonts">
<?=mssql_result($objQuery,$i,"ShopName");?>
</span></td>
<td align="center" bgcolor="#E9E9E9" class="fonts"><?=mssql_result($objQuery,$i,"Floor");?></td>
<td align="center" bgcolor="#E9E9E9" class="fonts"><?=mssql_result($objQuery,$i,"CategoryProduct");?></td>
<td align="center" bgcolor="#E9E9E9" class="fonts"><?=mssql_result($objQuery,$i,"DateShoping");
?></td>
<td align="center" bgcolor="#E9E9E9" class="fonts"><?=mssql_result($objQuery,$i,"Price");
?></td>
<td align="center" bgcolor="#E9E9E9" class="fonts">&nbsp;</td>
</tr>
<?
}
?>
</table></td>
</tr>
<tr bgcolor="#E9E9E9">
<td height="28" align="right" bgcolor="#444444"><span class="datepick-month-header">รวม
<?
include("../../config.inc.php") ;
$sum_rc="select sum(Price) as sum_paid from Redem WHERE (CategoryProduct LIKE '%".$_GET["txtKeyword1"]."%'
and Floor LIKE '%".$_GET["txtKeyword2"]."%')";
if($_GET["txtKeyword3"] != "" or $_GET["txtKeyword4"] != ""){
$objQuery .= " and (DateShoping between '".$_GET["txtKeyword3"]."' and '".$_GET["txtKeyword4"]."') ";
}
$query_sum=mssql_query($sum_rc);
$result = mssql_fetch_array($query_sum);
echo $result["sum_paid"];
?>

</span><br /></td>
</tr>
<tr bgcolor="#E9E9E9">
<td height="91" bgcolor="#666666"><p><span class="fonts">Total
<?= $Num_Rows;?>
Record :
<?=$Num_Pages;?>
Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}

mssql_close($objConnect);

?>
</span><br />
<a href="../userdetail.php"><br />
<span class="fonts">&lt;&lt;HOME&gt;&gt;</span></a><span class="fonts">&nbsp;&nbsp;</span><a href="../../logout.php"><span class="fonts">&lt;&lt;LOGOUT&gt;&gt;</span></a></p></td>
</tr>
</table>
<br>
</body>
</html>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-07 09:30:00 By : วันพีช
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : คำนวนราคาจากสินค้าภายใต้เงื่อนไข ผมใช้ LIKE 2 field และ between ผลการบวกมันก็ถูกครับ แต่บางทีบวกผิด ช่วยดูโค๊ดไห้หน่อย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่