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



Clound SSD Virtual Server

Ajax Shopping Cart (PHP+MySQL & ASP+Access)

Ajax Shopping Cart (PHP+MySQL & ASP+Access) ตัวอย่างการทำ Shopping Cart หรือ ตะกร้าสินค้า ใช้เทคโนโลยี่ Ajax เข้ามาช่วยในการจัดเก็บสินค้าลงในตะกร้า โดยในตัวอย่างผมใช้การเก็บลงใน Table ใช้ Session ID ในการระบุผู้ใช้แต่ล่ะคน และ เมื่อผู้ใช้ทำการบันทึกข้อมูลการสั่งซื้อ โปรแกรมจะสร้างหมายเลขสั่งซื้อจริงให้กับผู้ใช้แต่ล่ะคนที่ได้ทำการสั่งซื้อเข้ามาในระบบ

PHP + MySQL

AjaxPHPShoppingCart1.php

<?php
	/*** By Weerachai Nukitram ***/
	/***  http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<script language="JavaScript">
	   var HttPRequest = false;

	   function doCallAjax(ProductID,Qty) {
		  HttPRequest = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 HttPRequest = new XMLHttpRequest();
			 if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  } 
		  
		  if (!HttPRequest) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
	
		  var url = 'AjaxPHPShoppingCart2.php';
		  var pmeters = "tProductID=" + ProductID+
						"&tQty=" + Qty;
			HttPRequest.open('POST',url,true);

			HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			HttPRequest.setRequestHeader("Content-length", pmeters.length);
			HttPRequest.setRequestHeader("Connection", "close");
			HttPRequest.send(pmeters);
			
			
			HttPRequest.onreadystatechange = function()
			{

				 if(HttPRequest.readyState == 3)  // Loading Request
				  {
				   document.getElementById("mySpan").innerHTML = "Now is Loading...";
				  }

				 if(HttPRequest.readyState == 4) // Return Request
				  {			  
					  document.getElementById('mySpan').innerHTML = HttPRequest.responseText;
				  }				
			}

	   }
	   
	   function CheckOut()
	   {
	   window.location = 'AjaxPHPShoppingCart3.php';
	   }
	</script>
</head>
<body onLoad="JavaScript:doCallAjax('','')">
<h1>My Cart </h1>
<table width="680" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="234" valign="top">
	<?php
	$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
	$objDB = mysql_select_db("mydatabase");
	$strSQL = "SELECT * FROM product ORDER BY ProductID ASC ";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	echo"<table border=\"0\"  cellspacing=\"1\" cellpadding=\"1\"><tr>";	
	$intRows = 0;
	while($objResult = mysql_fetch_array($objQuery))
	{
	$intRows++;
	echo "<td>";									
	?>
	<img src="product/<?php echo $objResult["Picture"];?>" width="70" height="61" border="0">
	<center>
	<?php echo $objResult["ProductName"];?>
	<br>
	<?php echo $objResult["Price"]." Baht";?>
	<br>
	<input type="text" id="txt<?php echo $intRows;?>" value="" style="width:20px">
	<input type="button" value="Add" onClick="JavaScript:doCallAjax('<?php echo $objResult["ProductID"];?>', document.getElementById('txt<?php echo $intRows;?>').value);">
	</center>
	<?php
		echo"</td>";
		if(($intRows)%2==0)
		{
		echo"</tr>";
		}
		else
		{
		echo "<td>";
		}	
	}
	echo"</tr></table>";
	?>
	<?php
	mysql_close($objConnect);
	?>	
	</td>
    <td width="446" valign="top"><span id="mySpan"></span></td>
  </tr>
</table>
</body>
</html>









AjaxPHPShoppingCart2.php

<?php
	/*** By Weerachai Nukitram ***/
	/***  http://www.ThaiCreate.Com ***/

	session_start();
	$strProductID = $_POST["tProductID"];
	$strQty = $_POST["tQty"];	

	$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
	$objDB = mysql_select_db("mydatabase");

	if($strProductID != "" and $strQty  != "")
	{
		$strSQL = "INSERT INTO cart ";
		$strSQL .="(SID,ProductID,Qty) ";
		$strSQL .="VALUES ";
		$strSQL .="('".session_id()."','".$strProductID."','".$strQty."') ";
		$objQuery = mysql_query($strSQL);
	}
?>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart  WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
	$intRows ++;
	//*** Product ***//
	$strSQL = "SELECT * FROM product  WHERE ProductID = '".$objResult["ProductID"]."' ";
	$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$objResultPro = mysql_fetch_array($objQueryPro);
	$intTotal = $objResult["Qty"] * $objResultPro["Price"];
	$intSumTotal = $intSumTotal + $intTotal;
?>
  <tr>
    <td><div align="center"><?php echo $intRows;?></div></td>
    <td><?php echo $objResultPro["ProductName"];?></td>
    <td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
    <td><div align="center"><?php echo $objResult["Qty"];?></div></td>
    <td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
  </tr>
<?php
}
?>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
  </tr>
</table>
<?php
if($intSumTotal > 0)
{
?>
<br><input name="btnCheckOut" type="submit" id="btnCheckOut" value="Check Out" onClick="JavaScript:CheckOut();">
<?php
}
?>
</center>


AjaxPHPShoppingCart3.php

<?php
	/*** By Weerachai Nukitram ***/
	/***  http://www.ThaiCreate.Com ***/
	
	session_start();
	$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
	$objDB = mysql_select_db("mydatabase");	
	
	if($_GET["Action"]=="Save")
	{
		//*** Insert Order Header ***//
		$strSQL = "INSERT INTO cusorder ";
		$strSQL .="(Name,Email,Address,OrderDate) ";
		$strSQL .="VALUES ";
		$strSQL .="('".$_POST["txtName"]."','".$_POST["txtEmail"]."', '".$_POST["txtAddress"]."','".date("Y-m-d H:i:s")."') ";
		$objQuery = mysql_query($strSQL);	
		
		$intOrderID = mysql_insert_id();
		
		//*** Update Order Detail ***//
		$strSQL = "UPDATE cart SET OrderID = '".$intOrderID."' ,SID = '' WHERE SID = '".session_id()."'  ";
		$objQuery = mysql_query($strSQL);	
		
		header("location:AjaxPHPShoppingCart4.php?OrderID=".$intOrderID);
		exit();
	}
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart  WHERE SID = '".session_id()."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
	$intRows ++;
	//*** Product ***//
	$strSQL = "SELECT * FROM product  WHERE ProductID = '".$objResult["ProductID"]."' ";
	$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$objResultPro = mysql_fetch_array($objQueryPro);
	$intTotal = $objResult["Qty"] * $objResultPro["Price"];
	$intSumTotal = $intSumTotal + $intTotal;
?>
  <tr>
    <td><div align="center"><?php echo $intRows;?></div></td>
    <td><?php echo $objResultPro["ProductName"];?></td>
    <td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
    <td><div align="center"><?php echo $objResult["Qty"];?></div></td>
    <td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
  </tr>
<?php
}
?>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
  </tr>
</table>
<br>
<br>
<br>
<form action="AjaxPHPShoppingCart3.php?Action=Save" method="post" name="frmMain" id="frmMain">
  <table width="408" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td width="127">Name</td>
      <td width="275"><input name="txtName" type="text" id="txtName"></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input name="txtEmail" type="text" id="txtEmail"></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><textarea name="txtAddress" id="txtAddress"></textarea></td>
    </tr>
  </table>
  <br>
  <input name="btnSave" type="submit" id="btnSave" value="Save">
</form>
</center>
</body>
</html>


AjaxPHPShoppingCart4.php

<?php
	/*** By Weerachai Nukitram***/
	/***  http://www.ThaiCreate.Com ***/	

	session_start();
	$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
	$objDB = mysql_select_db("mydatabase");	

?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart [<?php echo $_GET["OrderID"];?>] </h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<?php
$intSumTotal = 0;
$intRows = 0;
$strSQL = "SELECT * FROM cart  WHERE OrderID = '".$_GET["OrderID"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
	$intRows ++;
	//*** Product ***//
	$strSQL = "SELECT * FROM product  WHERE ProductID = '".$objResult["ProductID"]."' ";
	$objQueryPro = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	$objResultPro = mysql_fetch_array($objQueryPro);
	$intTotal = $objResult["Qty"] * $objResultPro["Price"];
	$intSumTotal = $intSumTotal + $intTotal;
?>
  <tr>
    <td><div align="center"><?php echo $intRows;?></div></td>
    <td><?php echo $objResultPro["ProductName"];?></td>
    <td><div align="right"><?php echo number_format($objResultPro["Price"],2);?></div></td>
    <td><div align="center"><?php echo $objResult["Qty"];?></div></td>
    <td><div align="right"><?php echo number_format($intTotal,2);?></div></td>
  </tr>
<?php
}
?>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><?php echo number_format($intSumTotal,2);?></div></td>
  </tr>
</table>
</center>
</body>
</html>


Screenshot

Ajax Shopping Cart

Ajax Shopping Cart

Ajax Shopping Cart









ASP + Access

AjaxASPShoppingCart1.asp

<%
	'*** By Weerachai Nukitram ***'
	'***  http://www.ThaiCreate.Com ***'
	Option Explicit
%>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<script language="JavaScript">
	   var HttPRequest = false;

	   function doCallAjax(ProductID,Qty) {
		  HttPRequest = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 HttPRequest = new XMLHttpRequest();
			 if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  } 
		  
		  if (!HttPRequest) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
	
		  var url = 'AjaxASPShoppingCart2.asp';
		  var pmeters = "tProductID=" + ProductID+
						"&tQty=" + Qty;
			HttPRequest.open('POST',url,true);

			HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			HttPRequest.setRequestHeader("Content-length", pmeters.length);
			HttPRequest.setRequestHeader("Connection", "close");
			HttPRequest.send(pmeters);
			
			
			HttPRequest.onreadystatechange = function()
			{

				 if(HttPRequest.readyState == 3)  // Loading Request
				  {
				   document.getElementById("mySpan").innerHTML = "Now is Loading...";
				  }

				 if(HttPRequest.readyState == 4) // Return Request
				  {			  
					  document.getElementById('mySpan').innerHTML = HttPRequest.responseText;
				  }				
			}

	   }
	   
	   function CheckOut()
	   {
	   window.location = 'AjaxASPShoppingCart3.asp';
	   }
	</script>
</head>
<body onLoad="JavaScript:doCallAjax('','')">
<h1>My Cart </h1>
<table width="680" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="234" valign="top">
	<%
	Dim Conn,strSQL,objRec,intRows
	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""

	Response.Write("<table border='0'  cellspacing='1' cellpadding='1'><tr>")

	strSQL = "SELECT * FROM product ORDER BY ProductID ASC "
	Set objRec = Server.CreateObject("ADODB.Recordset")
	objRec.Open strSQL, Conn, 1,3

	intRows = 0
	While Not objRec.EOF
	intRows = intRows + 1
	Response.Write("<td>")									
	%>
	<img src="product/<%=objRec.Fields("Picture").Value%>" width="70" height="61" border="0">
	<center>
	<%=objRec.Fields("ProductName").Value%>
	<br>
	<%=objRec.Fields("Price").Value&" Baht"%>
	<br>
	<input type="text" id="txt<%=intRows%>" value="" style="width:20px">
	<input type="button" value="Add" onClick="JavaScript:doCallAjax('<%=objRec.Fields("ProductID").Value%>', document.getElementById('txt<%=intRows%>').value);">
	</center>
	<%
		Response.Write("</td>")
		If intRows Mod 2 = 0 Then
			Response.Write("</tr>")
		Else
			Response.Write("<td>")
		End IF	
	objRec.MoveNext
	Wend

	Response.Write("</tr></table>")
	objRec.Close()
	Conn.Close()
	Set objRec = Nothing
	Set Conn = Nothing 
	%>
	</td>
    <td width="446" valign="top"><span id="mySpan"></span></td>
  </tr>
</table>
</body>
</html>



AjaxASPShoppingCart2.asp

<%
	'*** By Weerachai Nukitram ***'
	'***  http://www.ThaiCreate.Com ***'

	Option Explicit

	Dim strProductID,strQty

	strProductID = Request.Form("tProductID")
	strQty = Request.Form("tQty")

	Dim Conn,strSQL,objExec
	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""

	If strProductID <> "" and strQty  <> "" Then
		strSQL = ""
		strSQL = strSQL &"INSERT INTO cart "
		strSQL = strSQL &"(SID,ProductID,Qty) "
		strSQL = strSQL &"VALUES "
		strSQL = strSQL &"('"&Session.SessionID&"','"&strProductID&"','"&strQty&"') "
		Set objExec = Conn.Execute(strSQL)
	End IF
%>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<%
Dim intTotal,intSumTotal,intRows,objRec,objRec2
intSumTotal = 0
intTotal = 0
intRows = 0
strSQL = "SELECT * FROM cart  WHERE SID = '"&Session.SessionID&"' "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3

	While Not objRec.EOF
	intRows = intRows + 1

	'*** Product ***'
	strSQL = "SELECT * FROM product  WHERE ProductID = "&objRec.Fields("ProductID").Value&" "
	Set objRec2 = Conn.Execute(strSQL)

	intTotal = objRec.Fields("Qty").Value * objRec2.Fields("Price").Value
	intSumTotal = intSumTotal + intTotal
%>
  <tr>
    <td><div align="center"><%=intRows%></div></td>
    <td><%=objRec2.Fields("ProductName")%></td>
    <td><div align="right"><%=FormatNumber(objRec2.Fields("Price"),2)%></div></td>
    <td><div align="center"><%=objRec.Fields("Qty")%></div></td>
    <td><div align="right"><%=FormatNumber(intTotal,2)%></div></td>
  </tr>
<%
	objRec.MoveNext
	Wend
%>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><%=FormatNumber(intSumTotal,2)%></div></td>
  </tr>
</table>
<%
If intSumTotal > 0 Then
%>
<br><input name="btnCheckOut" type="submit" id="btnCheckOut" value="Check Out" onClick="JavaScript:CheckOut();">
<%
End IF
%>
</center>



AjaxASPShoppingCart3.asp

<%
	'*** By Weerachai Nukitram ***'
	'***  http://www.ThaiCreate.Com ***'
	
	Dim Conn,strSQL,objRec1,objExec,intOrderID
	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
	
	If Request.QueryString("Action") = "Save" Then
		'*** Insert Order Header ***'
		strSQL = ""
		strSQL = strSQL &"INSERT INTO cusorder "
		strSQL = strSQL &"(Name,Email,Address,OrderDate) "
		strSQL = strSQL &"VALUES "
		strSQL = strSQL &"('"&Request.Form("txtName")&"', '"&Request.Form("txtEmail")&"','"&Request.Form("txtAddress")&"','"&Now&"') "
		Set objExec = Conn.Execute(strSQL)

		'*** OrderID ***'
		strSQL = "SELECT MAX(OrderID) As MaxOrderID FROM cusorder "
		Set objRec1 = Conn.Execute(strSQL)
		intOrderID = objRec1.Fields("MaxOrderID").Value
		
		'*** Update Order Detail ***//
		strSQL = "UPDATE cart SET OrderID = "&intOrderID&" ,SID = '' WHERE SID = '"&Session.SessionID&"'  "
		Set objExec = Conn.Execute(strSQL)	
		
		Response.Redirect("AjaxASPShoppingCart4.asp?OrderID="&intOrderID)
		Response.End
	End IF
%>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart</h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<%
Dim intTotal,intSumTotal,intRows,objRec2,objRec3
intSumTotal = 0
intTotal = 0
intRows = 0
strSQL = "SELECT * FROM cart  WHERE SID = '"&Session.SessionID&"' "
Set objRec2 = Server.CreateObject("ADODB.Recordset")
objRec2.Open strSQL, Conn, 1,3

	While Not objRec2.EOF
	intRows = intRows + 1

	'*** Product ***'
	strSQL = "SELECT * FROM product  WHERE ProductID = "&objRec2.Fields("ProductID").Value&" "
	Set objRec3 = Conn.Execute(strSQL)

	intTotal = objRec2.Fields("Qty").Value * objRec3.Fields("Price").Value
	intSumTotal = intSumTotal + intTotal
%>
  <tr>
    <td><div align="center"><%=intRows%></div></td>
    <td><%=objRec3.Fields("ProductName")%></td>
    <td><div align="right"><%=FormatNumber(objRec3.Fields("Price"),2)%></div></td>
    <td><div align="center"><%=objRec2.Fields("Qty")%></div></td>
    <td><div align="right"><%=FormatNumber(intTotal,2)%></div></td>
  </tr>
<%
	objRec2.MoveNext
	Wend
%>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><%=FormatNumber(intSumTotal,2)%></div></td>
  </tr>
</table>
<br>
<br>
<br>
<form action="AjaxASPShoppingCart3.asp?Action=Save" method="post" name="frmMain" id="frmMain">
  <table width="408" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td width="127">Name</td>
      <td width="275"><input name="txtName" type="text" id="txtName"></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input name="txtEmail" type="text" id="txtEmail"></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><textarea name="txtAddress" id="txtAddress"></textarea></td>
    </tr>
  </table>
  <br>
  <input name="btnSave" type="submit" id="btnSave" value="Save">
</form>
</center>
</body>
</html>



AjaxASPShoppingCart4.asp

<%
	'*** By Weerachai Nukitram ***'
	'***  http://www.ThaiCreate.Com ***'

	Dim Conn,strSQL
	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""

%>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<center>
<h1>Your Cart [<%=Request.QueryString("OrderID")%>] </h1>
<table width="408" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="51"><div align="center">ID</div></td>
    <td width="154" height="26"><div align="center">Product</div></td>
    <td width="69"><div align="center">Price</div></td>
    <td width="57"><div align="center">Qty</div></td>
    <td width="65"><div align="center">Total</div></td>
  </tr>
<%
Dim intTotal,intSumTotal,intRows,objRec,objRec2
intSumTotal = 0
intTotal = 0
intRows = 0
strSQL = "SELECT * FROM cart  WHERE OrderID = "&Request.QueryString("OrderID")&" "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3

	While Not objRec.EOF
	intRows = intRows + 1

	'*** Product ***'
	strSQL = "SELECT * FROM product  WHERE ProductID = "&objRec.Fields("ProductID").Value&" "
	Set objRec2 = Conn.Execute(strSQL)

	intTotal = objRec.Fields("Qty").Value * objRec2.Fields("Price").Value
	intSumTotal = intSumTotal + intTotal
%>
  <tr>
    <td><div align="center"><%=intRows%></div></td>
    <td><%=objRec2.Fields("ProductName")%></td>
    <td><div align="right"><%=FormatNumber(objRec2.Fields("Price"),2)%></div></td>
    <td><div align="center"><%=objRec.Fields("Qty")%></div></td>
    <td><div align="right"><%=FormatNumber(intTotal,2)%></div></td>
  </tr>
<%
	objRec.MoveNext
	Wend
%>    
  <tr>
    <td colspan="4"><div align="right">Total Amount </div></td>
    <td>
	<div align="right"><%=FormatNumber(intSumTotal,2)%></div></td>
  </tr>
</table>
</center>
</body>
</html>


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2009-01-24 08:02:43 / 2017-03-15 13:48:33
  Download : Download  Ajax Shopping Cart (PHP+MySQL & ASP+Access)
 Sponsored Links / Related

 
Ajax Introduction
Rating :

 
Ajax innerHTML & InnerText
Rating :

 
Ajax JavaScript & Event
Rating :

 
Ajax visibility hidden & visible
Rating :

 
Ajax Display Element
Rating :

 
Ajax Visibility & Display
Rating :

 
Ajax Disabled Element
Rating :

 
Ajax CreateElement
Rating :

 
Ajax setTimeOut
Rating :

 
Ajax responseText
Rating :

 
Ajax readyState
Rating :

 
Ajax Send Data Method POST (PHP & ASP)
Rating :

 
Ajax Send Data Method GET (PHP & ASP)
Rating :

 
Ajax Register Form (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Login (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Dropdownlist and Listmenu (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Upload file (PHP & ASP)
Rating :

 
Ajax Load Content (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Load Web Page (PHP & ASP)
Rating :

 
Ajax Loading Progress Icon
Rating :

 
Ajax List Record (PHP+MySQL & ASP+Access)
Rating :

 
Ajax List Record Paging/Pagination (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Add/Insert Record (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Edit/Update Record (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Delete Record (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Delete Record Part 2 (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Search Record (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Search Record Paging/Pagination (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Chat Room (PHP+Text & ASP+Text)
Rating :

 
Ajax Contact Form (PHP & ASP)
Rating :

 
Ajax Image Gallery (PHP & ASP)
Rating :

 
Ajax Open Text file (PHP & ASP)
Rating :

 
Ajax Autocomplete
Rating :

 
Ajax Check Username (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Auto Fill Textbox (PHP+MySQL & ASP+Access)
Rating :

 
Ajax Realtime (PHP+MySQL & ASP+Access)
Rating :

 
Ajax jQuery
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
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 อัตราราคา คลิกที่นี่