我有从mysql / php获取值的问题,如果有人可以帮助我,我将不胜感激。我的问题是我有一张名为专辑的表,在该表中我有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'>
感谢。
答案 0 :(得分:0)
好的,我发现了问题所在。我必须在我的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"];
答案 1 :(得分:0)
也许这效果更好; - )
$id = $_GET["id"]
$sql = mysqli_query ($dbconn, "SELECT id,album_name,artist,company,genre,price FROM albums WHERE id='$id'");
$result = mysqli_fetch_assoc($sql);
// ....