0

I have a button that runs a PHP function after the user onClicks. This is achieved using the POST method (as illustrated below). The user clicks on the button and the PHP function runs correctly, however, I want the user to be able to click the button multiple times and for the function to run multiple time. The function cannot over-ride its last result/outcome (so basically the result is echoed/printed each time the user clicks the button and the previous results are not overwritten).

Here is a section of my code, as follows:

 <?php
      function onClickArchive($detail_locator){
         for ($x = 0; $x <= 34; $x++) {
			 echo "<li><br />";
			  kal_generator($detail_locator);
			 echo "</li>";
	 }
		
      }
	
	if(isset($_POST['load_more'])){
	     onClickArchive($detail_locator);
        }

?>
 </ul>
<div id="reload_section">
    <center><br />
	  <form  method="post">
		<input type="submit" value="Load More" name="load_more" class="load_more_content" />
	  </form>
    </center>
</div>

1
  • Can u show kal_generator code ? Commented Mar 28, 2016 at 15:16

3 Answers 3

0

There are multiple methods to potentially solve this. One option would be to make the client send the existing data back when the button is pressed so you can append the new data to it without overwriting it.

The other option is to use AJAX to call the method and append to the existing data client side.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response @Chris, do you have any example you could possibly show me please?
0

Use/Try this PHP Function:

function setInterval($f, $milliseconds)
{
    $seconds=(int)$milliseconds/1000;
    while(true)
    {
        $f();
        sleep($seconds);
    }
}

Usage:

setInterval(function(){
    echo "I will echo many times!";
}, 1000);

It is like in setInterval in JavaScript

setInterval(Function(), seconds);

2 Comments

Thanks @CharlesCraft50, will this script update the PHP after 1000 milliseconds? - I am not sure if I understand the code
The function will call every 1 seconds.
0
you need to make use of Jquery. 
firstly use .load() method which will loads the data from server then use 
.append() method which will add the resulting data to the selected element.
$('.load_more_content').click({
$('#reload_section').append($('<div />').load('sample.php'));
});

1 Comment

Thanks @RaviKant Sharma, I tried to incorporate this, however it didn't seam to work correctly - any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.