Jump to content

[SOLVED] I want to store image locations in a database and then display the picture


vetman

Recommended Posts

I want to store image locations in a database and then display the picture using PHP. I am new to this so I need help please. My script shows the ID and file location, but no picture.

Here is my attempt:

 

<?php

// Make a MySQL Connection

include 'config.php';

 

$con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db(" ") or die(mysql_error());

 

echo "Connected to Database <br>";

 

// Retrieve all the data from the "pictures" table

$result = mysql_query("SELECT * FROM pictures")

or die(mysql_error());

 

// store the record of the "example" table into $row

echo "<table border='1' width='400'>";

echo "<tr> <th>id</th> <th>picture</th> </tr>";

// keeps getting the next row until there are no more to get

while($row = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table

echo "<tr><td>";

echo $row['id'];

echo "</td><td>";

echo $row['picture'];

echo "</td></tr>";

}

 

echo "</table>";

 

?>

It doesn't work like that. A browser downloads the html, parses it, finds image tags and the such (external resources) and then downloads them separately. Therefore you need to put the image reference in an image tag:

<img src='www.here.com/img.gip'></code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.