I have a variable $count = 10;
that I want to increase by 10 each time a user clicks <a id="load-more" href="#">Load more</a>
I have tried setting this up with onclick, variable equations and functions but I cannot seem to get it to increase.
Ultimately, I want the $count = 10;
to increase to $count = 20;
and so forth each time the user clicks.
If I understand your question properly, you're looking for a solution that makes use of AJAX. Something like this:
On the client:
$('#load-more').click(function () {
$.ajax({
type: 'POST',
url: "http://example.com/stuff.php",
async: true,
success: function(data) {
// Success! Do something with `data` here:
},
error: function (jqXHR, textStatus, errorThrown) {
// Error! You should probably display an error message here:
}
})
})
On the server (stuff.php):
<?php
$value = retrieveValue(); // Replace this with whatever means you are using to get the persisted value.
$value += 10; // Increment the value by 10 each time.
saveValue($value); // Replace this with whatever means you are using to save the persisted value.
?>
Keep in mind that in order to keep the value incrementing with each request you will have to persist the value in PHP by some means (database, session, file, etc.).
You will also need to load JQuery libs in your HTML file to use the above JavaScript code.