是否有可能添加这些了因为使用这种code总计?有可能、code

2023-09-10 15:53:27 作者:若即若离

是否有可能来计算总计与此code。我想compcase和caselight给予总计后按钮pressed。任何帮助将是AP preciated因为我不能工作了计算这一切的一个可行的办法。

的index.php

 函数casePrice(STR){
如果(STR ==){
的document.getElementById(txtHint)的innerHTML =。
返回;
}
如果(window.XMLHtt prequest){
// $ C $下IE7 +,火狐,Chrome,歌剧,Safari浏览器
XMLHTTP =新XMLHtt prequest();
}其他{// code对IE6,IE5
XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange =功能(){
如果(xmlhttp.readyState == 4和&安培; xmlhttp.status == 200){
  的document.getElementById(txtHint)的innerHTML = xmlhttp.responseText。
}
}
xmlhttp.open(GET,?caseprice.php Q =+ STR,真正的);
xmlhttp.send();
}

  功能caselightPrice(STR){
如果(STR ==){
的document.getElementById(txtHint)的innerHTML =。
返回;
}
如果(window.XMLHtt prequest){
// $ C $下IE7 +,火狐,Chrome,歌剧,Safari浏览器
XMLHTTP =新XMLHtt prequest();
}其他{// code对IE6,IE5
XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange =功能(){
如果(xmlhttp.readyState == 4和&安培; xmlhttp.status == 200){
  的document.getElementById(txtHint)的innerHTML = xmlhttp.responseText。
}
}
xmlhttp.open(GET,?caselightprice.php Q =+ STR,真正的);
xmlhttp.send();
}

< / SCRIPT>

<表单名称=PC方法=邮报ACTION =radiobutton.php>
<输入类型=无线电名称='compcase'的onchange =casePrice(THIS.VALUE)值=1/> NZXT幻影迷USB3.0全塔案例 - 白< BR />
<输入类型=无线电名称='compcase'的onchange =showPrice(THIS.VALUE)值='2'/>海盗船黑曜石750D大型立式机箱黑色< BR />
<输入类型=无线电名称='compcase'的onchange =showPrice(THIS.VALUE)值='3'/>酷冷至尊CM风暴骑兵黑色全塔游戏机箱< BR />< BR />

<输入类型=无线电名称='caselight'的onchange =caselightPrice(THIS.VALUE)值=1/>红< BR />
<输入类型=无线电名称='caselight'的onchange =caselightPrice(THIS.VALUE)值='2'/>绿色< BR />< BR />

< D​​IV ID =txtHint>< B>此处显示的价格与LT; / B>< / DIV>
 

caseprice.php

 < PHP
$ Q = INTVAL($ _ GET ['Q']);

$ CON = mysqli_connect('本地主机','根','','测试');
如果(!$ CON){
死亡(无法连接:mysqli_error($ CON)。);
}

mysqli_select_db($ CON,compcase);
$ SQL =SELECT * FROM compcase WHERE ID ='$ Q。';
$结果= mysqli_query($ CON,$ SQL);

而($行= mysqli_fetch_array($结果)){
回声< TR>中;
回声< TD>中。 $行['case_price']。 &所述; / TD>中;
回声< / TR>中;
}
回声< /表>;

mysqli_close($ CON);
?>
 

解决方案

你想要的总计的情况? 如果是这样,请您选择查询这样:

  SELECT SUM('case_price')AS grand_total从compcase WHERE ID ='$ Q。';
 
小程序没有入口 这些 场景 你可能还没用

然后,当你通过foreach循环,使用$行['grand_total'。

Is it possible to calculate a grand total with this code. I want compcase and caselight to give a grand total after the buttons are pressed. Any help would be appreciated as I can't work out a possible way of calculating it all.

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);
?>

解决方案

Do you want the grand total of the cases? If so, make your select query as such:

SELECT SUM('case_price') AS grand_total FROM compcase WHERE id = '".$q."'";

Then when you go through the foreach loop, use $row['grand_total'].