I’ve got a simple PHP image gallery where the PHP reads data from a MySQL database and organizes and links each one to a larger version. It works well but places too many images on the page.
I’m hoping someone can show me how to first split the images into multiple pages, as well as create navigation for users through the pages.
If it’s possible, I would also like the user to be able select how many images should be displayed per page, with a default of, say, 16.
Below is my current gallery’s code:
<?php
$mysql_link = mysql_connect("localhost", "root", "root");
mysql_select_db("new_arrivals_imgs") or die("Could not select database");
$query = mysql_query("SELECT `imgURL`,`imgTitle` FROM `images` ".
"ORDER BY `imgDate` DESC") or die(mysql_error());
if(!$query) {
echo "Cannot retrieve information from database.";
} else {
while($row = mysql_fetch_assoc($query)) {
echo "<li><a href='new_arrivals_img/".$row['imgURL'].
"' class='gallery' title='".$row['imgTitle'].
"'><img src='new_arrivals_img/thumbnails/".
$row['imgURL']."'></a></li>";
}
}
?>
Thanks in advance for your help.
You could add LIMIT to the end of your query string.
The first part of limit is where to start and the second is the length.
$limitcan be set by a select box or user text and$curPagecan be carried through url parameters.http://dev.mysql.com/doc/refman/5.1/en/select.html