$albums = get_albums_gallery();
foreach($albums as $album){
$album_id = $album['id'];
echo $album_id;
$images = get_images_gallery($album_id);
echo '<p>',$album['event'],'(', $album['count'],'images) <br>
',$album['description'],'...<br>
/
</p><img src="admin/uploads/',
$images['album'],'/',$images['id'],'.',
$images['ext'],'"title="Uploaded',
date(' DM Y/h:i',$images['timestamp']),
'"alt="hello" height="100px" width="100px"/>
'
;
}
上面的“img”应该显示相册内的一张图像作为循环播放的相册的缩略图。然而,$images['album'],$mages['id'] 等似乎都是未定义的索引。我已经包含了必要的连接文件。get_albums_gallery() 的代码
function get_albums_gallery(){
$albums = array();
$albums_query = mysql_query("
SELECT `albums`.`album_id`, `albums`.`timestamp`,`albums`.`event`,`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`
");
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'],
'event' => $albums_row['event']
);
}
return $albums;
}
和 get_images_gallery() 的代码
function get_images_gallery($album_id){
$album_id = (int)$album_id;
$images = array();
$image_query = mysql_query("SELECT `image_id`, `album_id`,`timestamp`,`ext` FROM `images` WHERE `album_id`=$album_id");
while($images_row = mysql_fetch_assoc($image_query)){
$images[] = array(
'id' => $images_row['image_id'],
'album'=> $images_row['album_id'],
'timestamp'=> $images_row['timestamp'],
'ext' => $images_row['ext']
);
}
return $images;
}
我不知道我哪里做错了,因为我已经在 get_images_gallery($album_id) 中传递了一个有效的 $album_id 参数。包含 $album['event'] 的行工作正常,直到它到达 img 标签并且我得到一个未定义的索引错误。提前致谢