0

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>
3
Contributors
9
Replies
11
Views
7 Years
Discussion Span
Last Post by facarroll
0

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.

0

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?

0

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.

0

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.

0

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.

0
<?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>

Edited by nonshatter: n/a

1

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 ?> >
Votes + Comments
Knowledgeable and helpful.
0
<?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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.