【发布时间】:2015-05-10 22:35:37
【问题描述】:
我正在尝试从 mysql 数据库中获取 img URL 并显示图像本身,而不是 URL 链接。
有没有办法将一些 HTML 连接到我在下面运行的 php 脚本中?
现在它可以正常显示图像 URL,但希望它显示它正在调用的实际图像。
<?php
$db = new mysqli('localhost', 'root', 'root', 'testdb');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT *
FROM `site_img`
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo $row['img_id'] . ' ' . $row['img_url'] . '<br />';
}
echo 'Total results: ' . $result->num_rows;
// Free result set
mysqli_free_result($result);
mysqli_close($db);
?>
【问题讨论】:
-
echo '<img src="'.$row['img_url'].'">'; -
完美,完美运行