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>
从数据库中获取图像
否,请检查查询您的错误是什么?先生,它只显示第一个图像,而不是allTryvar\u dump($row)
并将输出包含在您的帖子中