Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 若图像路径存储在数据库中,我想从数据库中检索所有图像_Php_Mysql - Fatal编程技术网

Php 若图像路径存储在数据库中,我想从数据库中检索所有图像

Php 若图像路径存储在数据库中,我想从数据库中检索所有图像,php,mysql,Php,Mysql,我的数据库中存储了三个图像路径,我想获取所有这些图像 请帮帮我 提前谢谢 我正在使用此代码,但它只显示第一个图像 <html> <body> <?php $servername = "localhost"; $username = "root"; $password = ""; $db="uni"; // Create connection $conn = new mysqli($servername, $username, $password,$db); // C

我的数据库中存储了三个图像路径,我想获取所有这些图像 请帮帮我 提前谢谢

我正在使用此代码,但它只显示第一个图像

<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db="uni";
// Create connection
$conn = new mysqli($servername, $username, $password,$db);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$result = mysqli_query($conn,("SELECT * FROM upload_img"));
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
{
echo "<img src='".$row['img_name']."' />";
echo "<br />";
}
?> 
</body>
</html>

我认为问题可能是使用了
img_name
而不是
img_path
作为图像的源,但作为旁白,您从一个面向对象的
mysqli连接开始,但切换到
过程性的
样式来运行查询等

<html>
    <head>
        <title>Get images from db</title>
    </head>
    <body>
        <?php

            $servername = "localhost";
            $username = "root";
            $password = "";
            $db="uni";

            $conn = new mysqli( $servername, $username, $password, $db );

            if ( $conn->connect_error ) die( "Connection failed: " . $conn->connect_error );

            $result = $conn->query( "SELECT * FROM `upload_img`" );

            while( $rs = $result->fetch_object() ){
                echo "
                <img src='{$rs->img_path}' />
                <br />";
            }
        ?> 
    </body>
</html>

从数据库中获取图像

否,请检查查询您的错误是什么?先生,它只显示第一个图像,而不是allTry
var\u dump($row)
并将输出包含在您的帖子中