3

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!!

1 Answer 1

3

Replace your :

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

With :

echo "<td><img src='".$cats_test['image']."' ></td>";
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! I've been pulling images from the web hoping to create the worlds biggest cat database. I'll get some reputation and up vote you answer. Hopefully there's some web scraping questions out there!
Done! Thanks again for your help Raphael!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.