Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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_Html_Mysql_Sql_Image - Fatal编程技术网

使用PHP从数据库检索多个图像

使用PHP从数据库检索多个图像,php,html,mysql,sql,image,Php,Html,Mysql,Sql,Image,我正在尝试使用PHP在屏幕上显示多个图像 我有一个数据库,它有到pictures文件夹中包含电影图片的每个图像的路径 下面是我的HTML文件 <!DOCTYPE html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title>

我正在尝试使用PHP在屏幕上显示多个图像

我有一个数据库,它有到
pictures
文件夹中包含电影图片的每个图像的路径

下面是我的HTML文件

<!DOCTYPE html>
    <head> 
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/navbarstyles.css" type="text/css">
        <link rel="stylesheet" href="css/home_page.css" type="text/css">
    </head>
    <body>


    <div class="nav">

        <nav class="header">
            <ul>
                <li><a href="home-page.html">Home</a></li>
                <li><a href="MyMovies.html">My Movies</a></li>
                <li><a href="AboutUsPage.html">About</a></li>
                <li><a href="Contact.html">Contact</a></li>
                <li><a href="CartPage.html">Cart</a></li>
                <li><a href="UserSettings.html">Settings</a></li>
            </ul>
        </nav>

    </div>

    <div class="browse">
        <div class="column">
            <input type="text" placeholder="Search" name="search"><br>

            <input type="checkbox" name="movies" value="releases" style="margin-bottom:15px">New Releases<br>
            <input type="checkbox" name="movies" value="popular" style="margin-bottom:15px">Popular<br>
            <input type="checkbox" name="movies" value="action" style="margin-bottom:15px">Action<br>
            <input type="checkbox" name="movies" value="adventure" style="margin-bottom:15px">Adventure<br>
            <input type="checkbox" name="movies" value="animated" style="margin-bottom:15px">Animated<br>
            <input type="checkbox" name="movies" value="comedy" style="margin-bottom:15px">Comedy<br>
            <input type="checkbox" name="movies" value="cooking" style="margin-bottom:15px">Cooking<br>
            <input type="checkbox" name="movies" value="drama" style="margin-bottom:15px">Drama<br>
            <input type="checkbox" name="movies" value="family" style="margin-bottom:15px">Family<br>
            <input type="checkbox" name="movies" value="horror" style="margin-bottom:15px">Horror<br>
            <input type="checkbox" name="movies" value="romance" style="margin-bottom:15px">Romance<br>
        </div>
    </div>

    <div class="movies">
        <div class="column">
            <img src="getImage.php" style="width:100%" />
        </div>        
    </div>
    </body>
</html>


新版本
流行的
行动
冒险
动画
喜剧
烹饪
戏剧
家庭
恐怖
浪漫
现在您可以看到,我有了getImage.php文件

<?php
  $servername = "localhost";
  $username = "usern";
  $password = "password";

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

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

  $sql = "select * from portfolio";
  $result = mysql_query($sql) or die("Invalid query: "  .mysql_error());
  while ($rows = mysql_fetch_array($result))
  ?>
  <img src="pictures/<?php echo $row['movie_paths']; ?>">

<?php

">

您引用了错误的变量。正确的变量是$rows而不是$row

 while ($rows = mysql_fetch_array($result))
 {
   ?>
   <img src="pictures/<?php echo $rows['movie_paths']; ?>">
 <?php
 }

您是否启用了错误报告,如果启用了,您将收到哪些错误?while之后的{loop@devlincarnate
未捕获错误:调用未定义函数mysql\u query()
是我的错误。我将更新问题。不能混合使用不同的mysql API。
$conn = new mysqli($servername, $username, $password);

$sql = "select * from portfolio";

if ($result = $conn-> query($sql)) 
{
  while ($row = $result -> fetch_row()) 
  {
    echo $row[0];
  }
}
$conn -> close();