Hi, everyone!
I need some urgent help with displaying images in a web page from a database. I've created the table picture in phpmydamin and it has these columns: id_picture( wich is the primary key), name, description and the pic_url ( wich contains the url path of the image for example: images/pic_1.jpeg). For now I just want to display the image, but instead it displays the url path as a text that is located in the pic_url column. This is the code I'm using:

<?php
mysql_connect("localhost","root","")
or die('Could not connect: ' . mysql_error());

mysql_select_db("art");
$result = mysql_query("SELECT * FROM picture");

?>

<?php

while($rows=mysql_fetch_array($result)){  
    $pictur=$rows["id_picture"];
    ?>

  <?php
     echo"<a > $rows[pic_url]</a>";
  ?>


<?php
}
mysql_close();
?>

Recommended Answers

All 5 Replies

Member Avatar for LastMitch

For now I just want to display the image, but instead it displays the url path as a text that is located in the pic_url column. This is the code I'm using:

Base on your code. I assume the image is in your database. You can just echo it out like this:

<img src="<?php echo $rows["id_picture"]; ?>" alt="Image from DB" />
commented: I agree with you ;) +0
Member Avatar for diafol

AS LM says. ALso you use:

echo"<a > $rows[pic_url]</a>";

This needs a href attribute.

I've always just stored the href themselves in the database and then ran the output as such:

<? php echo "<img id='idName' href='".$variableName."'/>"; ?>

Another option is to store the whole img tag in your database then doing a simle echo on the page in quotes like so :

<?php echo "'".$variable."'"; ?> 
Member Avatar for diafol

I've always just stored the href themselves in the database and then ran the output as such

I think you mean src with an img tag and href with an anchor tag?

Another option is to store the whole img tag in your database then doing a simle echo on the page in quotes like so :

I don't think you need anything as complicated:

<?php echo $variable; ?>

No need for all those quotes and concatenators.

Thank you so much for your help :) I'll try them and let you know :)

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.