【发布时间】:2015-12-26 08:21:34
【问题描述】:
我快疯了。我正在尝试将一个显示所有专辑缩略图图像和名称的页面中的变量传递到一个页面,该页面将使用该传递的变量显示该画廊中的所有图片,但该变量在目标页面的 url 中为空。我在网上和这个网站上看到过类似的案例,我已经应用了这些建议,但还是一样。这是列出缩略图并传递变量(id)的代码。
<?php
include ("config.php");
$conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD,dbname);
$albums = mysqli_query($conn,"SELECT * FROM albums");
if (mysqli_num_rows($albums) == 0) {
echo "You have no album to display. Please upload an album using the form above to get started. ";
}
else{
echo "Albums created so far:<br><br>";
echo "<table rows = '4'><tr>";
while ($thumb = mysqli_fetch_array($albums)) {
echo '<td><a href ="view.php?id="'.$thumb['id'].'"/><img src = "'.$thumb['thumbnail'].'"/><br>'.$thumb['album_name'].'<br>'.$thumb['id'].'</a></td>';
}
echo "</tr></table>";
}
?>
获取传递变量的代码如下:
<?php
include("config.php");
$conn = mysqli_connect(DB_DSN,DB_USERNAME,DB_PASSWORD);
$db = mysqli_select_db($conn,dbname);
if (isset($_GET['id'])) {
$album_id = $_GET['id'];
$pic = "SELECT * FROM photos WHERE album_id ='$album_id'";
$picQuery = mysqli_query($conn,$pic);
if (!$picQuery) {
exit();
}
if (mysqli_num_rows($picQuery) == 0) {
echo "Sorry, no Pictures to display for this album";
}
else{
echo "Pictures in the gallery:<br><br>";
while ($result = mysqli_fetch_assoc($picQuery)) {
echo "<img src='".$result['photo_path']."'/>";
}
}
}
?>
请帮忙,因为我过去两天一直在努力解决问题。
【问题讨论】:
-
尝试删除锚点上的双引号。
..<a href ="view.php?id='.$thumb['id'].'"/>..... -
谢谢一百万!!!!!!现在工作得很好。再次感谢。