I'm trying to display an array of images by using the following code but no images are displayed. The images are in a folder named images. Is there some problem using a variable in a path name? Or am I doing something else that is wrong?
The variable $thumbnail refers to a column of filenames. If I echo that variable as an array, I get the required filenames. I just cannot turn that into an array of images.

<?php
$query = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); 
 
while($row1 = mysql_fetch_array($query))
{
$thumbnail .= $row1['title']."<br />";
}
?>
                 <table>
                    <tr>
                      <td><img src="images/<?php echo $thumbnail ?>" /></td>
                    </tr>
                  </table>

Recommended Answers

All 9 Replies

When you click "view source" on the outputted page, what does <img src="images/<?php echo $thumbnail ?>" /> display?

If $thumbnail doesn't have a file extension then it's going to be just linking to a folder as the image source.

Can you show us an example of what is contained within $thumbnail? Try removing the <br> and the '.=' may want to be changed to '='

You are allowed to use variables in path names. Are you using a windows or linux host?

When you click "view source" on the outputted page, what does <img src="images/<?php echo $thumbnail ?>" /> display?

If $thumbnail doesn't have a file extension then it's going to be just linking to a folder as the image source.

It displays

<img src="wood_tool_images/{$thumbnail}" />

If I echo $thumbnail it has a jpg extension.

try this? and report back the results!

<img src="images/"<?php echo $thumbnail ?> />

Can you show us an example of what is contained within $thumbnail? Try removing the <br> and the '.=' may want to be changed to '='

You are allowed to use variables in path names. Are you using a windows or linux host?

Thanks. $thumbnail echoed produces filename.jpg. I tried those changes and the first image in the array displays, but only that one. The <br /> set up the next line in the display.
I'm using wamp server.

try this? and report back the results!

<img src="images/"<?php echo $thumbnail ?> />

This change displays an array of the filenames, and strangely, leaves out the first filename in the array. It also leaves a closing tag in the display.

<?php

$query = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."'                                                                                                                                                    AND egroup1='"."1"."' ORDER BY title ASC"); 
?>

<table>
<tr>
while($row1 = mysql_fetch_assoc($query))
{
        $thumbnail = $row1['title'];
    ?>
        <td><img src=<?php echo "images/". $thumbnail ?> /></td>
    <?php
}
?>
</tr>
</table>

The easiest way to check if the path is correct is to right click where the broken image is displayed, then 'copy Image URL', then paste the shortcut which will tell you whether the path is output correctly.

If it looks correct, but still doesn't display the image, then try adding the full path to the location. E.g.

<img src=<?php echo "C://xampp/htdocs/images/". $thumbnail ?> >
commented: Knowledgeable and helpful. +1
<?php

$query = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."'                                                                                                                                                    AND egroup1='"."1"."' ORDER BY title ASC"); 
?>

<table>
<tr>
while($row1 = mysql_fetch_assoc($query))
{
        $thumbnail = $row1['title'];
    ?>
        <td><img src=<?php echo "images/". $thumbnail ?> /></td>
    <?php
}
?>
</tr>
</table>

You got it. I've got a really messy page now, but I'll sort it in the morning. Thanks a million. I'm not sure what you did though. I'll have to study up. If you like, you can see where I'm trying to go at www.safetytestingonline.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.