What you are looking for is pagination.
Google it and you will find plenty of websites to help you.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
Hello,
create another column for "imageid" that will be incrementing id, make a variable named, "$currentid" which will hold the value of the first "imageid" from the table. now on each press of next and previous link, just write simple code for retrieving image from the database having "$currentid" incremented or decremented as per previous or next link is clicked.
Hope you will find this helpful.
emarshah
Junior Poster in Training
61 posts since Jan 2008
Reputation Points: 10
Solved Threads: 6
Pagination is what I would use here. It seperates the data into pages (which are part of the same page) via a _GET parameter. Pagination has nothing to do with thumbs.
<?php
$user = 'asdfasdf';
$pass = 'asasdfasdf'
//Variables
$thispage = 'index.php';
$perPage = 1; //number of images to show per page
$link = mysql_connect('localhost',$user,$pass) or die('Could Not Connect: ' . mysql_error());
mysql_select_db('dataBase',$link) or die('Could not select database: ' . mysql_error());
$page = 1;
if ( isset( $_GET['page'] ) ) {
$page = (int) $_GET['page'];
}
$query = mysql_query("SELECT COUNT(*) FROM `images`",$link);
list( $total ) = mysql_fetch_row( $query );
$total = ceil( $total / $perPage );
$start = ( $perPage * ( $page - 1 ) );
$limit = '';
$show = true;
if ( $total > 1 ) {
$limit = " LIMIT {$start}, {$perPage}";
}
else {
$show = false;
}
$query = mysql_query("SELECT * FROM `images` ORDER BY `title`{$limit}");
while( $row = mysql_fetch_assoc( $query ) ) {
echo "<img src=\"{$row['path']}\" alt=\"{$row['title']}\" title=\"{$row['id']}\" />";
}
if ( $show ) {
$prev = $page - 1;
$next = $page + 1;
if ( $prev > 0 ) {
echo "<a href=\"{$thispage}?page={$prev}\">[PREV]</a>";
}
if ( $next < $total ) {
echo "<a href=\"{$thispage}?page={$next}\">[NEXT]</a>";
}
}
?>
The code is untested and probably has some errors. I haven't had to create a pagination script by hand in awhile.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
change the $thispage variable at the top of the script to the name of you page.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
Have you thought about using ready-made scripts? Highslide is pretty good as it's got a slideshow mode to cycle through your images. Just a thought.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080