gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:14:42 26 4
gpt4 key购买 nike

我是一名学生,我有一个项目要做,我们在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com