php - 如何引用我的 PHP 文件的图像路径?

标签 php html mysql

我是一名学生,我有一个项目要做,我们在 MySql 中创建了一个名为 Video_Game_Shop 的数据库。然后我们必须使用 PHP 和 HTML 将它连接到一个网站。我们必须在一个页面上显示我们数据库中列出的所有游戏。所以我们通过调用一个按价格订购游戏的过程来做到这一点。这就是我遇到的问题。我们现在需要在页面上显示这些游戏中的每一个的图像。到目前为止,我已经为我们列出的每个游戏下载了图片,但我不知道如何完成该任务。我听说过一些输入图像路径或使用 BLOB 文件类型的方法,但我不知道该怎么做。我将添加 PHP 文件,以便您可以更轻松地了解我的情况。如果你能帮助我,我将不胜感激。 :)

<!DOCTYPE html>
<html>
<link rel="stylesheet"                   href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
<style>
    h1 {font-family:Serif; font-size:22px; text-align:center}
    p {font-family:Serif; font-size:16px}
    .container {
        width: 100%;
        clear: both;
        opacity: 1
    }
    input[type=number] {
        border:2px #ffo; 
        opacity:0.2}
    input[type=text] {
        border:2px #ff0; 
        opacity:0.2}
    input[type=date] {
        border:2px #ff0; 
        opacity:0.2}

</style>
<h1>videogames</h1>

    <head>
        <title>videogames</title>
        <link rel="stylesheet" href="css/table.css" type="text/css" />
    </head>
    <body background="http://i.imgur.com/yGkEuwZ.jpg">
        <?php
        require_once 'user.php';
        try {
            $conn = new PDO("mysql:host=$host;dbname=$dbname",
                            $username, $password);
            // execute the stored procedure
            $sql = 'CALL List_game_by_price()';
            $q = $conn->query($sql);
            $q->setFetchMode(PDO::FETCH_ASSOC);
        } catch (PDOException $pe) {
            die("Error occurred:" . $pe->getMessage());
        }
        ?>
        <div class="container">
        <table border="1" align="center" width="90%">
            <tr>
                <th>GameID</th>
                <th>Name/th>
                <th>Developer</th>
                <th>Publisher</th>
                <th>ESRB</th>
                <th>Relase Date</th>
                <th>Platform</th>
                <th>Genre</th>
                <th>Language</th>
                <th>Price</th>
            </tr>
        <?php while ($r = $q->fetch()): ?>
                <tr>
                    <td><?php echo $r['GameID'] ?></td>
                    <td><?php echo $r['Name'] ?> </td>
                    <td><?php echo $r['Developer'] ?></td>
                    <td><?php echo $r['Publisher']?></td>
                    <td><?php echo $r['ESRB'] ?></td>
                    <td><?php echo date_format ($r['Relase Date']) ?></td>
                    <td><?php echo $r['Platform'] ?></td>
                    <td><?php echo $r['Genre'] ?></td>
                    <td><?php echo $r ['Language'] ?></td>
                    <td><?php echo $r['Price'] ?></td>
                    </td>
                </tr>
        <?php endwhile; ?>
        </table>
        </div>
    </body>
</html>

最佳答案

一个根本不更改数据库的快速解决方案是将图像上传到 FTP 并重命名它们的名称以匹配 GameID。

示例:将质量效应 2_600x400.jpg 更改为 1.jpg。

在你的 fetch 中(你显示来自 base 的数据的地方)只需添加另一个这样的东西

<td><?php echo '<img src="path/to/'.$r['GameID'].'.jpg" />' ?></td>

关于php - 如何引用我的 PHP 文件的图像路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34694949/

相关文章:

html - 如何获得 :before element open-quote to be inline with div

mysql - 更新mysql表

html - 如何在表格中放置我的文本(表格已在页面上居中)

mysql - 如何选择与表 A 的条目相关的表 B 的多个条目

mysql - Upsert - 如果存在则更新,否则插入 MySQL

php - 如何在 PHP 中通过 HTTPS 发出 POST 请求?

当我不执行 var_dump 时,php 不加载脚本

php - AJAX MySQL 更改输入值

PHP邮件功能无法向Gmail帐户发送电子邮件?

javascript - Angular JS 代码不工作