在页面上显示数据库中的照片时出现问题

时间:2019-07-11 00:19:38

标签: php css sql

我在页面上显示数据库中的照片时遇到问题。我在数据库列image_src =“ ../GameForest/gamephoto/gta5.jpg”中创建了一个路径。路径是正确的,我检查了几次。

//这是显示数据库中所有数据的类

<?php
    class Game extends Dbh {

        public function gameDiv() {
            $id = $_GET['id'];
            $stmt = $this->connect()->query("SELECT g.game_id, g.game_name, g.image_src, g.genre_id, g.developer_id, g.release_date, g.platfrom_id, g.game_price,  g.game_description, g.processor, g.graphic, g.ram\n" . "FROM game AS g\n" . "LEFT JOIN genre AS z\n" . "ON g.genre_id = z.id WHERE game_id = '$id'");
            while ($row = $stmt->fetch()) {

                echo "<div class='gameName'><h2>" . $row['game_name'] . "</h2></div>";

                echo "<div class='buying'><p>" . $row['game_price'] . "&euro;</p><a href='bought.php'><button>Buy Game</button></a></div>";


//This next echo is for displaying photo from database:
                echo "<div class='gamePhoto'><img>" . $row['image_src'] . "</img></div>";

                echo "<div class='gameGenre'><b>Genre: </b><p>" . $row['genre_id'] . "</p></div>";

                echo "<div class='gameDeveloper'><b>Created by: </b><p>" . $row['developer_id'] . "</p></div>";

                echo "<div class='gamePlatform'><b>Platform: </b><p>" . $row['platfrom_id'] . "</p></div>";

                echo "<div class='gameRdate'><b>Release date: </b><p>" . $row['release_date'] . "</p></div>";

                echo "<div class='gameDescription'><b>Description: </b><p>" . $row['game_description'] . "</p></div>";

                echo "<div class='sysRequirements'><p>Recommended System Requirements:</p><b>Processor:</b><p>" . $row['processor'] . "</p>" . "  Heading <b>Graphic:</b><p>" . $row['graphic'] . "</p>" . " <b>RAM:</b><p>" . $row['ram'] . "</p>";
            }
        }
}

**//This is instance for previous class:**
<?php
    #istance for printing information about a Game
    $game = new Game;
    echo $game->gameDiv();
?>

**//This is CSS code of that photo:**

.gamePhoto {
        margin: 10px 0 20px 10%;
        width: 200px;
        height: 400px;
        float: left;
    }

    .gamePhoto img {
        width: 500px;
        height: 600px;    
    }

?>

我希望数据库中有一张图片,但是我只得到一个灰色框,该图像实际上应该低于它写为“ ../ GameForest / gamephoto / gta5.jpg”(我在基础中编写的路径) 。     其余数据库数据正常显示,这只是图像问题。     在另一页(和其他班级)上,正常显示来自同一数据库的同一张图片,我没有问题。

2 个答案:

答案 0 :(得分:2)

img是内联块,像<img src="" />

一样使用

答案 1 :(得分:1)

更改此

<img>" . $row['image_src'] . "</img>

对此

<img src=" . $row['image_src'] . ">