0

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();
?>
4
Contributors
5
Replies
49
Views
4 Years
Discussion Span
Last Post by sophy27
1

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" />
Votes + Comments
I agree with you ;)
0

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."'"; ?> 
0

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.

0

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

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.