There are literally hundreds of JS plug-ins that have that functionality and don't rely on GET requests to achieve the result (which your php code does), not to mention php code inside of html code, which is really tough to read and look through. (Mind you, I used to do the same thing myself and it looked rather sad) Anyways, let's see if we can get you a solution for your issue with pure JS:
Code:
<script type="text/javascript">
min_pic = 1;
curr_pic = 1; //this is obviously where you initialize the variables, see how it's pretty much the same thing as your PHP code.
max_pic = 10;
pic_prefix = "P";
pic_format = ".jpg";
function prevbtn () { // function when clicking the "previous" button
if (curr_pic == min_pic)
curr_pic = max_pic;
else
curr_pic = curr_pic - 1;
var img = document.getElementById("imgcnt");
img.src = "images/" +pic_prefix + curr_pic + pic_format;
var imgcount = document.getElementById("imgcount");
imgcount.textContent = "Image " + curr_pic + " of " + max_pic;
}
function nextbtn() { // function to fire when the "Next" button is clicked.
if (curr_pic == max_pic)
curr_pic = min_pic;
else
curr_pic = curr_pic + 1;
var img = document.getElementById("imgcnt");
img.src = "images/" + pic_prefix + curr_pic + pic_format;
var imgcount = document.getElementById("imgcount");
imgcount.textContent = "Image " + curr_pic + " of " + max_pic;
}
</script>
And certainly your HTML mark-up would be changed like this:
Code:
<input type="button" onclick="prevbtn()" value="previous" />
<img id="imgcnt" src="images/p1.jpg" />
<input type="button" onclick="nextbtn()" value="next" />
<center><div id="imgcount">Image 1 of 10</div></center>
And there it is, you will find some formatting issues... but I'm sure you can take care of those on your own. Enjoy.