I need to write a script in PHP that will display 20 thumbnails at a time, and if you click on one of the thumbnails it will adjust to show a range of 20 thumbnails with the selected one in the center. There are hundreds of thumbnails in the MySQL database so it needs to find the record and display 9 records before and 10 records after.
The idea I had involves 3 separate MySQL queries. One to get the selected thumb, one to get the ones before and one to get the thumbnails after.
How can I do this with just one query? My thumbnail database’s key field is alphabetical so there is no number associated with the record, but I could add a integer ID field if I need to.
You should use limit to offset the result of your queries. With that and a simple count (to get the total elements in the table) you should be able to get your pages right =).
Here’s the reference:
http://dev.mysql.com/doc/refman/5.1/en/select.html
http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html
Also, I found this useful PHP/MySQL paging tutorial that uses limit
http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx
you’d only need to substract the 9 thumbnails and show 20 records to get the desired results.
good luck!