Bu bir okul projesi için olduğunu. Ben kullanıcı bir mouseover yaptığında değerler ProdTotal PHP işlevi Toplam Quanity ve Toplam Tutar tablonun son sütununda göstermek için almaya çalışıyorum. Bunu yapmak için Ajax kullanmak zorunda. Bu yüzden Far ne var. Bu tamamen yeni ve tamamen kaybetti duyuyorum. Bazı yardım seviniriz.
Ajaxfunctions.js:
function getXMLHttp()
{
var xmlHttp
try
{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
function MakeRequest(product)
{
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
HandleResponse(xmlHttp.responseText);
}
}
}
xmlHttp.open("GET", "prodTotal.php?product=+_product", true);
xmlHttp.send(null);
}
function HandleResponse(response)
{
document.getElementById('totalqty').innerHTML = response;
document.getElementByID('totaldol').innerHTML = response;
}
Bu PRODTOTAL fonksiyonu ve tablodaki mouseover olaylarla PHP Class.
<?php
Class CarsClass {
private $user = 'php06';
private $pwd = 'php06';
private $dbConn;
function __construct($db='classicmodels') {
//Create connection to MySQL database requested, if blank just connect up.
$this->dbConn = new mysqli('localhost', $this->user, $this->pwd, $db);
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select count(*) as 'custcount' from customers";
$result = $this->dbConn->query($query);
$row = $result->fetch_assoc();
$custCount = $row['custcount'];
print "Connected to DB $db as user $this->user<br><br> Number of Rows $custCount<br><br>";
}
function __destruct(){
mysqli_close();
Print "DB closed by user <br><br>";
}
function header(){
echo "Midterm Exam Script 2 Header<br><br>";
}
function display(){
$totqty = 0;
$totamt = 0;
//get row from WB_Resident Table
$query = "select productCode,productName,productDescription,quantityInStock,buyPrice,MSRP from products";
$result = $this->dbConn->query($query);
?>
<table id="midterm2">
<tr>
<th colspan="13">Product Database Table</th>
</tr>
<tr>
<th width="2%">product Code</th>
<th width="10%">product Name</th>
<th width="10%">product Description</th>
<th width="10%">quantity in stock</th>
<th width="10%">buy Price</th>
<th width="2%">MSRP</th>
<th width="10%">Total Quantity</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th width="10%">Total Dollars</th>
</tr>
<?php
while($row = $result->fetch_assoc()):
$producta = $row["productCode"];
//list($totqty, $totamt) = $this->ProdTotal($producta);
?>
<tr>
<td>
<?php echo $row["productCode"]; ?>
</td>
<td>
<?php echo $row["productName"];?>
</td>
<td>
<?php echo $row["productDescription"]; ?>
</td>
<td>
<?php echo $row["quantityInStock"]; ?>
</td>
<td>
<?php echo $row["buyPrice"]; ?>
</td>
<td>
<?php echo $row["MSRP"]; ?>
</td>
<td>
<div id ="totalqty" onmouseover="MakeRequest($producta)"></div>
<div id ="totaldol" onmouseover="MakeRequest($producta)"></div>
</td>
</tr>
<?php
endwhile;
?>
</table>
<?php
}
function footer(){
echo "Midterm Exam Script 3 Footer<br><br>";
}
function ProdTotal($product){
$query = "select RTRIM(productCode) as productt, quantityOrdered, priceEach from orderdetails order by productt";
$result = $this->dbConn->query($query);
while($row = $result->fetch_assoc()){
if ($row["productt"] == $product){
$total = $row["quantityOrdered"] * $row["priceEach"];
$totqty = $totqty + $row["quantityOrdered"];
$totamt = $totamt + $total;
}
}
return array($totqty, $totamt);
}
}
?>
Bu sınıf çağırır.
<html>
<head>
<title>Midterm2 Script 4</title>
<link rel="stylesheet" type="text/css" href="midterm2.css" />
<script src="ajax_functions.js" type="text/javascript"></script>
</head>
<body>
<?php
require 'CarsClass4.php';
$obj1= new CarsClass('classicmodels');
$obj1->header();
$obj1->display();
$obj1->footer();
?>
</body>
</html>