Jump to content

Showing a picture in a table with PHP

DeagleMaster

I am trying to get a php file to show the picture in a table and not just the file name listed in mysql. 

This is what i have now:

 

    if($row = $sth->fetch())
    {
        ?>
        <br><br>
        <table>
            <tr>
                <th>Bilde</th>
                <th>Navn</th>
                <th>Rase</th>
                <th>Beskrivelse</th>
            </tr>
            <tr>
                <td><?php echo $row->bilde;?></td> ------------------------------------------------This is where I would like the picture to be shown. Now it just shows me the file name.
                <td><?php echo $row->navn;?></td>
                <td><?php echo $row->rase;?></td>
                <td><?php echo $row->beskrivelse;?></td>
            </tr>

        </table>


<?php

Link to comment
Share on other sites

Link to post
Share on other sites

You need to wrap it in an <img> tag for the browser to interpret it as an image. 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, FlappyBoobs said:

You need to wrap it in an <img> tag for the browser to interpret it as an image. 

I have tried that multiple times but it doesn't work for some reason.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, C2dan88 said:

What did you try? It should be like


<td><img src="<?php echo $row->bilde;?>" /></td>

This will output the filename inside the src attribute of the img tag.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img

 

This is what i get now. It looks like it might not be able to fetch the file name. It managed to do it before, but than it just displayed the file name as text.

 

image.thumb.png.1e9febfeee5792b0e7b2ec5bd0917fae.png

image.thumb.png.baca200901603a78f53d0c8915c4467e.png

Link to comment
Share on other sites

Link to post
Share on other sites

Are the images located in the same folder as sokfunksjon.php. If they are in different folder you need to prepend the path before echo'ing $row->bilde

 

What is the value stored in $row->bilde, can you show outputted HTML (right click > view source)

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, C2dan88 said:

Are the images located in the same folder as sokfunksjon.php. If they are in different folder you need to prepend the path before echo'ing $row->bilde

 

What is the value stored in $row->bilde, can you show outputted HTML (right click > view source)

The folder with the pictures are located in the same folder as the php file. I know I have to write in the folder name, but I am not sure how to do this.

This works when the picture is outside the folder in the same folder as the php file:

<img src="<?php echo $row->bilde;?>"/>

 

I tried writing the path like this but it didn't work:

<img src="<?php echo $row->bilder/bilde;?>"/>

"bilder" is the folder name and "bilde" is the name of the row i mysql.

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, C2dan88 said:

Are the images located in the same folder as sokfunksjon.php. If they are in different folder you need to prepend the path before echo'ing $row->bilde

 

What is the value stored in $row->bilde, can you show outputted HTML (right click > view source)

Fixed it by doing this:

<img src="bilder/<?php echo $row->bilde;?>"/>

 

Thanks for all the help.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×