Display an image from a MySQL database using PHP

Nosmig

New to this but loving it. I have a database of URLs of pictures of cats that I want to display in a webpage. I wrote some php to do this but all I'm seeing it the URL of the image and not the image itself. Here is my full code:

<html>
<body>
<h1>Katz!!</h1>

<!--Connect to Database-->
<?php
$db_host = "localhost";
$db_username = "Alex";
$db_pass = "";
$db_name = "cats";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mySQL");
@mysql_select_db("$db_name") or die ("No database");

$sql="SELECT * FROM cats_test";
$records = mysql_query($sql);
?>

<!--Populate table from database-->
<table  border="2" cellpadding="1" cellspacing="1">
<tr>
    <th>cat table</th>
</tr>
<?php
while($cats_test=mysql_fetch_assoc($records)) {
    echo "<tr>";
    echo "<td>".$cats_test['image']."</td>";
    echo "</tr>";
}
?>
</table>
</body>
</html>

As you can see, the database name is "cats" with a table called "cats_test" that holds all of the images in a column called "image" you can find a screenshot of that here

You can also see the URLs being displayed instead of images here

I've probably done something really stupid, so would appreciate any help you guys might have!!

Raphaël Vigée

Replace your :

echo "<td>".$cats_test['image']."</td>";

With :

echo "<td><img src='".$cats_test['image']."' ></td>";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PHP MySQL display image from database

Display image from MySQL using PHP not working

How to retrieve image file paths from mysql database and display the images using php

Upload image in MYSQL database & display it using PHP with Swift

Not being able to display Image from MySQL Database in PHP

Display Image on website from mysql database via php

image display from database in php

Display image from database php

How to display image from mysql database using spring mvc

Using image paths from database to display images in php

Format using MYSQL Date Retrieved from Database and Display in PHP file

How to display a link from the MySql database in html using jquery or php

How to display images from database mysql using php?

How to display Decimal and Date Arrays from MySQL database using php

How to display data from database into line graph using php and mysql?

Basic Image display from Database in PHP

How to display an image from a database using ajax

PHP / MYSQL - display images from database issue

how to display image from mysql in php

How to I display image from mysql PHP

Display data from mysql database using a table

upload image from submit form to mysql database and display image in div?

Insert a random image in mysql database using php

Display info from a database on a webpage using php

How to get the an image from mysql database in php

How can I display data from MYSQL database using HTML table from a PHP file?

How to display a particular clicked image from multiple image fetched from database using while loop in php, and javascript for displaying?

How to display image from database instead of image path using jQuery

How to display an image stored in Mysql database with special date not by id (php)