gpt4 book ai didi

PHP Mysql $Id问题 Cannot Retrieve Data Using only $id as parameter

转载 作者:行者123 更新时间:2023-11-30 22:25:27 25 4
gpt4 key购买 nike

我在从 mysql/php 获取值时遇到问题,如果有人能帮助我,我将不胜感激。我的问题是我有一个名为 albums 的表,在该表中我有 6 列,分别是 id、album_name、艺术家、公司、流派、价格。我在我的 index.php 中写了这段代码:

<?php
$query = mysqli_query ($dbconn, "SELECT * FROM albums ORDER BY id DESC LIMIT 4 OFFSET 8");
while($result = mysqli_fetch_assoc($query)){
$id = $result["id"];
$album_name = $result["album_name"];
$img = $result["image"];
$artist = $result["artist"];
$company = $result["company"];
$genre = $result["genre"];
$price = $result["price"];

echo "<div class='col-md-3 col-xs-6'>
<a href ='album_page.php?id=$id' target='_blank' class='box_link_hover'><div class='box'>
<div class='inside_box'>
<div class='small_title'>
<h4>$album_name</h4>
</div>
<div class='photo_box'>
<img src=$img class='img_dim'>
</div>
<div class='info'>
<p>Artist: $artist</p>
<p>Company: $company</p>
<p>Genre: $genre</p>
<p>Price: $price</p>
</div>
</div>
<div class='buy_now'>
<p>Buy Now</p></a>
</div>
</div>
</div>";
}
?>

我有另一个名为 album_page.php 的页面,我将其从我的 index.php 发送到 album.php 的 $id 以便从我的数据库中获取数据。在我的 album_page.php 页面中,我有这段代码:

<?php
$sql = mysqli_query ($dbconn, "SELECT id,album_name,artist,company,genre,price FROM albums WHERE id='$id'");
$id = $_GET["id"];
$album_name = $_GET["album_name"];
$artist = $_GET["artist"];
$company = $_GET["company"];
$genre = $_GET["genre"];
$price = $_GET["price"];
echo "<div class='col-md-4 right_box'>";
echo "<p>Album Name: $album_name</p>";
echo "<p>Artist: $artist</p>";
echo "<p>Company: $company</p>";
echo "<p>Genre: $genre</p>";
echo "<p>Price: $$price</p>";
echo "<div class='buy_now_box'>Buy Now</div>";
echo "</div>";
?>

我想做的是从我的 index.php 发送那个 $Id 并使用 $_GET 获取我的 album_page.php 中的所有数据。例如,我想使用 $id = 5 从我的数据库中获取所有数据。例如,我已经尝试使用许多参数:

<a href ='album_page.php?id=$id&image=$img&album_name=$album_name&artist=$artist&company=$company&genre=$genre&price=$price&buy_now=$buy'target='_blank' class='box_link_hover'><div class='box'>

它工作正常,但我想只使用这个得到相同的结果:

<a href ='album_page.php?id=$id' target='_blank' class='box_link_hover'><div class='box'>

谢谢。

最佳答案

好的,我已经找到问题所在了。我必须在我的 album_page.php 中这样写才能获取数据:

$sql = mysqli_query ($dbconn, "SELECT id,album_name,artist,company,genre,price FROM albums WHERE id='$id'");
$result = mysqli_fetch_assoc($sql);
$id = $_GET["id"];
$album_name = $result["album_name"];
$artist = $result["artist"];
$company = $result["company"];
$genre = $result["genre"];
$price = $result["price"];

关于PHP Mysql $Id问题 Cannot Retrieve Data Using only $id as parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35380484/

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