正确显示图像

时间:2019-02-11 09:53:24

标签: php html postgresql

我如何以正确的方式显示图像,当我将其放置在显示图像而不是不同图像时,当前很难一一显示。 这是我从数据库中选择详细信息后要在其中显示图像的代码。

PHP代码

  <div class="panel-body" id="panelsection">
  <?php while($row1 = pg_fetch_array($result1)){ ?>
    <div id="categorymoviesection">
        <img src="<?php echo $row1[2]; ?>" height="300" width="200">
        <h5 style="color: #FFFFFF"><?php echo $row1[1]; ?></h5>
        <a href = "moviedetails.php?movieid=<?php echo $row1[0];?>" class = "btn btn-default" id="btndefault" role = "button" style="width: 200px">
            More details
        </a>
    </div>
    <?php  } ?>
  </div>

所有代码

<!DOCTYPE html>
<?php 
    session_start();
    $name = "";
    $userid = "";
    if(array_key_exists('name', $_SESSION) && array_key_exists('userid', $_SESSION)){
        $name = $_SESSION['name'];
        $userid = $_SESSION['userid'];
    }

?>
<html lang="en">
<head>
    <?php $page_title = "All Movies" ?>
    <?php include("includes/resources.php");?>
    <?php include ("includes/navbar2.php");?>
      <?php
      require('connect.php');
        $query = "SELECT M.MovieID, M.Name, rank.average
                    FROM (
                        SELECT SUM(W.Rating)/count(W.Rating) AS average, M.MovieID AS mo
                        FROM Movie M, Watches W
                        WHERE M.MovieID = W.MovieID
                        GROUP BY M.MovieID)rank, Movie M
                    WHERE M.MovieID = rank.mo 
                    GROUP BY rank.average, rank.mo, M.Name, M.MovieID
                    ORDER BY M.Name";

        $result = pg_query($link,$query);
        $stmt = pg_prepare($link, 'ps',$query); 

      ?>

</head>

<body style="background-color: #212121; padding-bottom: 30px;">
    <div class="container">

    <h1 style="color: #FFFFFF; margin-left: -45px;"> 
    All available Products:
    </h1>

        <div class="row clearfix">

    <!--Thumbnail for the movies-->

    <div class = "row"  id="thumbnailsection">

   <?php while($row = pg_fetch_array($result)) { ?>


   <div class = "col-sm-6 col-md-3" id="indivthumbnail" >
      <div class = "thumbnail" id="indivthumbnail2" >
         <img src = "<?php  echo $row[3]; ?> " alt = "Generic placeholder thumbnail">
      </div>

      <div class = "caption" id="caption2">
         <h4> <?php echo $row[1]; ?> </h4>
         <p>Rating: <?php  echo $row[2];   ?> </p>

         <p>
         <?php if (1==1){?>
            <a href = "watchedlist.php?movieid=<?php echo $row[0];?>&userid=<?php echo $userid ?>" class = "btn btn-primary" id="btnprimary" role = "button">
               Bought
            </a> 
         <?php } else { ?>
            <a href = "watchedlist.php?movieid=<?php echo $row[0];?>&userid=<?php echo $userid ?>" class = "btn btn-primary" id="btnprimary" role = "button">
               Add to wishlist
            </a> 
            <?php } ?>
            <a href = "moviedetails.php?movieid=<?php echo $row[0];?>" class = "btn btn-default" id="btndefault" role = "button">
               More details
            </a>
         </p>

      </div>
   </div>

 <?php  } ?>
  </div>
  </div>
  </div>

</body>
</html>

结果即时获得 image result

非常感谢您的帮助

2 个答案:

答案 0 :(得分:0)

清除空格。我认为这是个问题。

<div class = "thumbnail" id="indivthumbnail2" >
     <img src = "<?php  echo $row[3]; ?> " alt = "Generic placeholder thumbnail">
</div>

答案 1 :(得分:0)

您没有添加watchedlist.phpmoviedetails.php的代码,但请确保在HTTP响应上设置正确的MIME类型,如下所示:

$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));

switch( $file_extension ) {
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpeg"; break;
    default:
}

header('Content-type: ' . $ctype);
readfile($file);