silverglade Posted July 6, 2011 Share Posted July 6, 2011 Hi, I have tried to make a minor change to the output of an image gallery I have, to make thumbnails. I would like to have users have their own galleries, but that is beyond me now, just trying to make thumbnails generated as output from the database. Below is the code. You can see what I have done. Please let me know what I can do as all it does is outputs the names of the image files, and not the image itself. thank you. EDIT: I have no idea where the images are being uploaded. I don't see a directory. But the images display on other pages with other code. Strange. <?php require_once('globals.php'); $query = sprintf('select image_id, filename from images'); $result = mysql_query($query, $db); $images = array(); while ($row = mysql_fetch_array($result)) { $id = $row['image_id']; $images[$id] = $row['filename']; } ?> <html> <head> <title>Uploaded Images</title> </head> <body> <div> <h1>Uploaded Images</h1> <p> <a href="upload.php">Upload an image</a> </p> <ul> <?php if (count($images) == 0) { ?> <li>No uploaded images found</li> <?php } else foreach ($images as $id => $filename) { ?> <li> <!--<a href="view.php?id=<?php echo "<img src = '$id' width='100' height='100'/> <br />" ?>">-->//THIS IS WHAT I CHANGED TO TRY TO OUTPUT 100X100 THUMBS IN A COLUMN AFTER EACHOTHER. <?php echo htmlSpecialChars($filename) ?> </a> </li> <?php } ?> </ul> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/ Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 Now I don't know how php is displaying my images on the live server if the images are not being uploaded to a directory. They are not on the server, yet are being displayed. Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238750 Share on other sites More sharing options...
jcbones Posted July 6, 2011 Share Posted July 6, 2011 They are in a blob field in your database. At least that is what the script is telling me. Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238752 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 Blob fields store the actual image data? thank you. I am still working on a way to output the images. thanks. I can't figure out how to output the images. Please any help appreciated. I have tried many things. Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238753 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 well that was a pain in the ass, but I solved it when I looked up how to output blob images. I came across a great forum post on a forum. here is the magic code. its magic! <img src="view.php?id=<?php echo $id ?>"/><br />//OUTPUTS THE IMAGES ALL IN A COLUMN Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238766 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 Does anyone know how I could make a new column of thumbnails once the number of images reaches 8 for this? I don't know how. Please any help greatly aprpeciated. thank you. Here is my code so far. <?php require_once('globals.php'); $query = sprintf('select image_id, filename from images'); $result = mysql_query($query, $db); $images = array(); while ($row = mysql_fetch_array($result)) { $id = $row['image_id']; $images[$id] = $row['filename']; } ?> <html> <head> <title>Uploaded Images</title> </head> <body> <div> <h1>Uploaded Images</h1> <p> <a href="upload.php">Upload an image</a> </p> <ul> <?php if (count($images) == 0) { ?> <li>No uploaded images found</li> <?php } else foreach ($images as $id => $filename) { ?> <table cellpadding="10px"><tr><td> <a href="view.php?id=<?php echo $id ?>"> <img src="view.php?id=<?php echo $id ?> " width="100" height="100"/> </a><br /> </tr></td> </table> <!-- <a href="view.php?id=<?php //echo $id ?>">--> <?php //echo htmlSpecialChars($filename) ?> <!-- </a>--> <?php } ?><!--end of loop--> </ul> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238775 Share on other sites More sharing options...
jcbones Posted July 6, 2011 Share Posted July 6, 2011 Try this, and see if it works: <div style="float:left;width:110px;"> <?php $i = 0; if (count($images) == 0) { ?> <li>No uploaded images found</li> <?php } else foreach ($images as $id => $filename) { ?> <table cellpadding="10px"><tr><td> <a href="view.php?id=<?php echo $id ?>"> <img src="view.php?id=<?php echo $id ?> " width="100" height="100"/> </a><br /> </tr></td> </table> <?php if((++$i % == 0) { echo '</div><div style="float:left;width:110px;">'; } //if the current incremented value of $i, divided by 8, has a remainder of 0, write a new division.?> <!-- <a href="view.php?id=<?php //echo $id ?>">--> <?php //echo htmlSpecialChars($filename) ?> <!-- </a>--> <?php } ?><!--end of loop--> </div> Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238784 Share on other sites More sharing options...
silverglade Posted July 6, 2011 Author Share Posted July 6, 2011 Jcbones you are a genius! THANK YOU so much!!!!, I was using if statements to echo out the tables and ended up getting pathetically messed up copies. I can really learn from that code you gave me, because I do understand CSS, and don't like the idea of resorting to tables, as I know that is outdated. Thank you!! That made my night now I can go to sleep. LOL. :) :) (works perfectly, 8 per column, new column when reaches 8, awesome.) Quote Link to comment https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/#findComment-1238786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.