在PHP中从URL显示img&;MySQL

在PHP中从URL显示img&;MySQL,php,html,mysql,Php,Html,Mysql,我试图从mysql数据库中获取一个img URL,并显示图像本身,而不是URL链接 有没有一种方法可以将一些HTML连接到下面运行的php脚本中 现在它显示图像URL很好,但希望它显示它调用的实际图像 <?php $db = new mysqli('localhost', 'root', 'root', 'testdb'); if($db->connect_errno > 0){ die('Una

我试图从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);
            ?>

您可以在循环中插入html
img
标记

<?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()){
?>
            <img name="<?php echo $row['img_id'] ?>" src="<?php $row['img_url'] ?>" /> <br />
<?php
            }
            echo 'Total results: ' . $result->num_rows;

            // Free result set
            mysqli_free_result($result);

            mysqli_close($db);
?>

“/>

echo';
完美,效果完美