我正在尝试制作一个图片库。里面有带有图像的专辑,在索引页面上我想显示女巫专辑,当你点击它时,你会去那个专辑。我可以显示专辑名称,但我想显示这些专辑以及该专辑中的图像,并具有随机功能。我希望你明白我想做什么。问题是我无法访问图像。
我有两个关联数组,一个用于相册,一个用于图像。专辑的那个看起来像这样;
function get_albums() {
$albums = array();
$albums_query = mysql_query("
SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`,
LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
FROM `albums`
LEFT JOIN `images`
ON `albums`.`album_id` = `images`.`album_id`
GROUP BY `albums`.`album_id`
")or die(mysql_error());
while ($albums_row = mysql_fetch_assoc($albums_query)) {
$albums[] = array(
'id' => $albums_row['album_id'],
'timestamp' => $albums_row['timestamp'],
'name' => $albums_row['name'],
'description' => $albums_row['description'],
'count' => $albums_row['image_count']
);
}
return $albums;
}
对于图像,它看起来像这样;
function get_images($album_id) {
$album_id = (int)$album_id;
$images = array();
$image_query = mysql_query("SELECT `image_id`, `image_name`, `album_id`, `timestamp`, `ext` FROM `images` WHERE `album_id`=$album_id");
while ($images_row = mysql_fetch_assoc($image_query)) {
echo $images_row['image_id'];
$images[] = array(
'id' => $images_row['image_id'],
'img_name' => $images_row['image_name'],
'album' => $images_row['album_id'],
'timestamp' => $images_row['timestamp'],
'ext' => $images_row['ext']
);
}
return $images;
}
我认为在使用左连接函数的 get_albums 函数中,我可以通过像这样添加图像名称和扩展名来访问图像;
while ($albums_row = mysql_fetch_assoc($albums_query)) {
$albums[] = array(
'id' => $albums_row['album_id'],
'timestamp' => $albums_row['timestamp'],
'name' => $albums_row['name'],
'description' => $albums_row['description'],
'count' => $albums_row['image_count'],
'img_name' => $albums_row['image_name'],
'ext' => $albums_row['ext']
);
然后像这样在索引页面中使用它;
$albums = get_albums();
if (isset($albums)) {
foreach ($albums as $album) {
echo '<a href="view_album.php?album_id=', $album["id"], '"><img src="uploads/thumbs/', $album["id"] ,'/', $album['img_name'],'.', $album["ext"],'" />', $album['name'], '</a>';
}
}
但结果是这样的; http://www.robcnossen.nl/
我究竟做错了什么?