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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.