I am trying to show images from database with next previous button.
here's my code:
<?PHP
session_start();
$page = "voting.php";
include ('dbconnect.php');
$q = "SELECT * FROM vote_frames";
$r = mysql_query($q);
while($row = mysql_fetch_array($r)){
$i_array[] = $row['frame_pic'];
$i_array1[] = $row['frame_pic1'];
$i_array2[] = $row['frame_pic2'];
$id_array[] = $row['frame_id'];
}
$fpp = 1;
$num_images = count($i_array);
$image_path = "frames/";
$y = $fpp;
if(!isset($_GET['first'])){
$first = 0;
}else{
$first = (int) $_GET['first'];
}
$x = $num_images - 1;
$z = $x - $y;
if($first>$z) {
$first = $z;
}
$last = $first + $fpp;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
</head>
<body>
<div>
<?PHP
$i = $first;
$prev = $first-1;
$next = $first +1;
if($prev<0){ $prev = 0; }
?><a href="<?PHP echo $page; ?>?first=<?PHP echo $prev; ?>">Previous</a><?PHP
while($i<$last) {
$f = $image_path . $i_array[$i];
$f1 = $image_path . $i_array1[$i];
$f2 = $image_path . $i_array2[$i];
?>
<img src="<?PHP echo $f; ?>">
<img src="<?PHP echo $f1; ?>">
<img src="<?PHP echo $f2; ?>">
<?PHP
$i++;
}
?><a href="<?PHP echo $page; ?>?first=<?PHP echo $next; ?>"><Next</a><?PHP
?>
</div>
</body>
</html>
Images are displaying but with a strange behavior that last record is not showing. Actually for testing when I echoed id of current showing record, it shows next's id so record is having id of next's.
I know I can do it with jquery w/o any issue but I must use a way to store current showing pic's id in session so I can show current showing and its next picture's vote count in the graph below.
Any take on it?