Jump to content

PHP Ajax help needed!


tom92

Recommended Posts

Okay... I'm sort of an aax newbie. I wrote up this small script. Basicly what it does is sends the numeric value to the php file and then inserts that value into Mysql.

 

I can do that fine but then when I try to display the SUM() of all the values i'm having problems.

 

Here's my script...

 


<html>
<head>
<script type="text/javascript">

function XMLHttp(){
// XMLHttp Request here...
}

var ajaxRequest;

function insertValue(value){

ajaxRequest.open("GET","insertValue.php?value=" + value,true);
ajaxRequest.send(null);
}

</script>
</head>

<body>
<p id="show_total"><!-- This where i'd want to show the SUM() of all the values --></p>
<a href="javascript:insertValue(5)">Add value</a>
</body>
</html>

 

Okay theres the code. When the user hits the Add value link I want to display the total inside the p tags.

Link to comment
https://forums.phpfreaks.com/topic/135698-php-ajax-help-needed/
Share on other sites

in insertValue.php file write a query which return sum of the field and return the response to you

 

Hint :SUM() is a function in mysql

 

when the response will received at client end in responseText you can do something like

 

if(readystate == 4)

{

  document.getElementById('show_total').value=responseText

}

 

i think above hints are sufficient for you to start !!!

 

thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/135698-php-ajax-help-needed/#findComment-711359
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.