I have some images in folder and name of the images in a file. I want to display the images according to the buttons clicked.
<!DOCTYPE html>
<html>
<head>
<title>Your Album</title>
</head>
<body>
<form method="post">
<input type="submit" name="first" value="FIRST">
<input type="submit" name="previous" value="PREVIOUS">
<input type="submit" name="next" value="NEXT">
<input type="submit" name="last" value="LAST">
<input type="submit" name="dele" value="DELETE">
</form>
<br>
<?php
$fp = fopen("imgname.csv","r");
$line = fread($fp,filesize("imgname.csv"));
$item = explode("
", $line);
$count;
$sizecsv = sizeof($item);
if(isset($_POST['next'])) {
$count++;
echo "<img src='images/$item[$count]' width='250px'>";
echo "<br>","Image No: ",$count+1;
}
if(isset($_POST['previous'])) {
$count--;
echo "<img src='images/$item[$count]' width='250px'>";
echo "<br>","Image No: ",$count+1;
}
if(isset($_POST['first'])) {
$count = 0;
echo "<img src='images/$item[$count]' width='250px'>";
echo "<br>","Image No: ",$count+1;
}
if(isset($_POST['last'])) {
$count = $item[$sizecsv-1];
echo "<img src='images/$item[$count]' width='250px'>";
echo "<br>","Image No: ",$count+1;
}
?>
</body>
</html>
This is my code. I store the image names in an array and try to manipulate the index according to the button clicked. This works for "FIRST" button but not for anything else. I don't understand the problem. Is it that every time a click a button the page reloads and value of $count is lost. Please give a solution. Also I am new to php so if you can keep it simple then it would be helpful. Thanks in advance.