vetman Posted May 4, 2008 Share Posted May 4, 2008 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/104101-solved-i-want-to-store-image-locations-in-a-database-and-then-display-the-picture/ Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 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] Link to comment https://forums.phpfreaks.com/topic/104101-solved-i-want-to-store-image-locations-in-a-database-and-then-display-the-picture/#findComment-532941 Share on other sites More sharing options...
vetman Posted May 5, 2008 Author Share Posted May 5, 2008 This is what I used to make it work! Thanks echo "<img src='".$row['picture']."'>"; Link to comment https://forums.phpfreaks.com/topic/104101-solved-i-want-to-store-image-locations-in-a-database-and-then-display-the-picture/#findComment-533294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.