music_lp90 Posted April 25, 2007 Share Posted April 25, 2007 Hi, I'm pretty new to php, but I have two people who are asking me to build sites for them that will have photo galleries. I am able to load pictures into a MySQL database, but I'm uncertain of how to retrieve the thumbnail images, display them in a html table and link them to the larger images they represent. Can someone tell me what I need to research in order to do this? Would it be some type of query followed by pagination (which I know nothing about)?Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2007 Share Posted April 25, 2007 Are the image files in the database or just the filenames? What does the database look like? Link to comment Share on other sites More sharing options...
zppblood Posted April 25, 2007 Share Posted April 25, 2007 Are the image files in the database or just the filenames? What does the database look like?I guess musiclp_90 was wanting something similar to what the author of the other thread uploading gallery wanted. Link to comment Share on other sites More sharing options...
music_lp90 Posted April 25, 2007 Author Share Posted April 25, 2007 Yes, it is in a MySQL database using medium blob to store the data. However, I might be going a different direction where they are not stored in the database. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 26, 2007 Share Posted April 26, 2007 Well, then it depends on the database. You can read the binary data straight from the database, send the correct content-type, and print the data if the image is in the database. Otherwise you would just get the filename and write a link to the image. In either case, the parent (larger) image should be stored in the same record as the thumbnail so that you know which image the thumnail links to.If you have the binary data in a field called "thumb", and it is a jpeg, you would display it like this: <?php$sql = ...$result = mysql_query($sql);$row = mysql_fetch_assoc($result);header("Content-type: image/jpeg");header("Content-length: " . strlen($row['thumb']));echo $row['thumb'];?> Link to comment Share on other sites More sharing options...
music_lp90 Posted April 26, 2007 Author Share Posted April 26, 2007 Ok, I'm going to try this way. I've got sort of what I wanted to do working without using the database, but I want to try it this way and see if I can get it to work and then try to do pagination so it will display only a certain number of images per page. Thanks for the help.Here's how I had the table set up:`id` int(11) NOT NULL AUTO_INCREMENT, Primary Key `title` varchar(64) character SET utf8 NOT NULL,`ext` varchar(8) character SET utf8 NOT NULL,`image_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,`data` mediumblob NOT NULL, I'll add a thumb field, do I make the thumb field a medium blob as well? Link to comment Share on other sites More sharing options...
music_lp90 Posted April 26, 2007 Author Share Posted April 26, 2007 Well, I'm not having any luck figuring out how to submit two image files (large and thumbnail) into the same row of a MySQL table. I added two fields to the table one is a thumb field and the other is a $ext2 field. Link to comment Share on other sites More sharing options...
reportingsjr Posted April 26, 2007 Share Posted April 26, 2007 just make one column called data like you have, and duplicate it with a different name. Then you can resize it with something like the gd library and put that into the database also. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 26, 2007 Share Posted April 26, 2007 Actually, you don't even need to store the thumbnail in the database if you don't want to. You can just read the full-size image and resize it to whatever size you want when you display it. It's a little complex, but you can do it.Also, if you aren't sure how to get the image data in the first place, you can use the results of the file_get_contents function to store in the database. All you need is a string containing the file data, and that function will give it to you. You can also use fopen and fread.If you want to see an example of a gallery that stores images in the database and resizes and things like that, download this:http://www.manchine.net/steve/files/gallery.zip Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.