Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/241164-trying-to-make-image-thumbnails/
Share on other sites

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

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>

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>

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.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.