|
|
|
ช่วยดู Code ให้หน่อยนะครับ พอดีลบไม่ได้ ไม่แน่ใจจริงๆว่าผิดตรงไหน |
|
|
|
|
|
|
|
File : AjaxPHPDeleteRecord1
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(ID) {
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 = 'AjaxPHPDeleteRecord2.php';
var pmeters = "tID=" + ID;
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;
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('LIST','');">
<h1>My Customer</h1>
<form name="frmMain">
<span id="mySpan"></span>
</form>
</body>
</html>
File : AjaxPHPDeleteRecord2
Code (PHP)
<?php
$strID = $_POST["ProductID"];
include("connect.php");
if($strMode == "DELETE")
{
$strSQL = "DELETE FROM cart ";
$strSQL .="WHERE ProductID = '".$strID."' ";
$objQuery = mysql_query($strSQL);
}
?>
<table width="392" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="42"><div align="center">ID</div></td>
<td width="128" height="26"><div align="center">Product</div></td>
<td width="59"><div align="center">Price</div></td>
<td width="48"><div align="center">Qty</div></td>
<td width="56"><div align="center">Total</div></td>
<td width="45">ลบ</td>
</tr>
<?
$intSumTotal = 0;
$intQtyTotal =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;
$intQtyTotal += $objResult["Qty"];
?>
<tr>
<td><div align="center">
<?=$intRows;?>
</div></td>
<td><?=$objResultPro["ProductName"];?>
<?=$objResultPro["ProductID"];?></td>
<td><div align="right">
<?=number_format($objResultPro["Price"],2);?>
</div></td>
<td><div align="center">
<?=$objResult["Qty"];?>
</div></td>
<td><div align="right">
<?=number_format($intTotal,2);?>
</div></td>
<td align="center"><a href="JavaScript:doCallAjax('DELETE','<?=$objResult["ProductID"];?>');">Del</a></td>
</tr>
<?
}
?>
<tr>
<td colspan="3"><div align="center">Total</div></td>
<td align="center"><?=number_format($intQtyTotal,2);?></td>
<td align="right"><?=number_format($intSumTotal,2);?></td>
<td align="right"> </td>
</tr>
</table>
<?
mysql_close($con);
?>
ไม่แน่ใจจริงๆว่าผิดตรงไหน เพราะลบไม่ได้
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2010-09-09 07:19:39 |
By :
evekrub |
View :
733 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เราส่งข้อมูลเข้าไปหา funcion 2 ตัวไม่ใช้หรือ แล้วตอนรับทำไมรับตัวเดียว
function doCallAjax(str,ID)
แล้วก็บรรทัด var pmeters = "tID=" + ID; น่าจะเป็น
var pmeters = "tMode=" + str+"&tID=" + ID;
|
|
|
|
|
Date :
2010-09-09 08:45:18 |
By :
somparn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|