-2
是否可以使用此代码计算总计。按下按钮后,我想让compcase和caselight提供总计。任何帮助将不胜感激,因为我不能找出一种可能的方式来计算这一切。是否可以使用此代码将它们总计添加为总计?
的index.php
function casePrice(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","caseprice.php?q="+str,true);
xmlhttp.send();
}
function caselightPrice(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","caselightprice.php?q="+str,true);
xmlhttp.send();
}
</script>
<Form name ="pc" Method ="Post" ACTION ="radiobutton.php">
<Input type = 'Radio' Name ='compcase' onchange="casePrice(this.value)" value= '1' />NZXT Phantom Enthusiast USB3.0 Full Tower Case - White <br />
<Input type = 'Radio' Name ='compcase' onchange="showPrice(this.value)" value= '2' />Corsair Obsidian 750D Large Tower Case Black <br />
<Input type = 'Radio' Name ='compcase' onchange="showPrice(this.value)" value= '3' />Cooler Master CM Storm Trooper Black Full Tower Gaming Case <br /><br />
<Input type = 'Radio' Name ='caselight' onchange="caselightPrice(this.value)" value= '1' />Red<br />
<Input type = 'Radio' Name ='caselight' onchange="caselightPrice(this.value)" value= '2' />Green <br /><br />
<div id="txtHint"><b>Show price here</b></div>
caseprice.php
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','test');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"compcase");
$sql="SELECT * FROM compcase WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['case_price'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
我希望case_price和caselight_price合计为总计。这两个单选按钮: NZXT幻影爱好者USB3.0全塔式机箱 - 白色
和红色
– 2014-09-03 13:40:30
当我这样做时,该值显示为0 – 2014-09-03 15:37:40