Aim of my Program:
- On my index.php file, an image is displayed.
- I want that, when i user clicks that image, a new image should be displayed.
- And when he clicks the new image, another new image should appear.
What have i done till now ?
<?php
$mycolor = array("red.jpg", "green.jpg", "blue.jpg");
$i = 0;
$cc = $mycolor[$i++];
?>
<form method="post" action="index2.php">
<input type="image" src="<?php echo $cc; ?>">
</form>
I know what the error is. Whenever, the page is reloaded, the variable $i is initialized to ZERO. How, do i fix that. How can I retain the incremented value after the image is clicked ?
Also, I have no Javascript Knowledge. So, if possible explain me in terms of php.
You have different possibilities to remember $i. e.g:
$_GET: http://php.net/manual/en/reserved.variables.get.phpCookies: http://php.net/manual/en/function.setcookie.php
Sessions: http://php.net/manual/en/features.sessions.php
There is also no necessity to use a form for this problem. Just wrap the image with a hyperlink and modify the url by incrementing the parameter (index.php?i=1, index.php?i=2, index.php?i=3 and so on).