user2116516
user2116516

Reputation: 139

Display image with image URL from MySQL

I really don't know what I'm doing here. I can display the url from the database but I can't figure out how to add the html code

$sql = "SELECT IMG_URL, Birthdate, FirstName, LastName FROM Student";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "IMG: " . $row["IMG_URL"]. " Birthdate: " . $row["Birthdate"]. " - Name: " . $row["FirstName"]. " " . $row["LastName"]. "<br>";
    }

Upvotes: 0

Views: 1643

Answers (1)

omnichad
omnichad

Reputation: 1655

Right now, you're not outputting any HTML at all from this code. Insert an <img> tag around the outputted image:

    echo "IMG: <img src=\"" . $row["IMG_URL"]. "\" /> Birthdate: " . $row["Birthdate"]. " - Name: " . $row["FirstName"]. " " . $row["LastName"]. "<br>";

Upvotes: 1

Related Questions