$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()PHP,從相冊檢索特定圖像作爲該特定專輯
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標記,並且我得到一個未定義的索引錯誤。在此先感謝
您正在創建'get_images_gallery多維數組'$圖像[] =陣列(...)'()',但你試圖訪問一個單級陣列'$圖像[ ...]'。嘗試使用'$圖像訪問它,[0] [ '專輯']'/'$圖像[0] [ '身份證']'/'$圖像[0] [ '分機']' – Sean
你也改變'$圖片[] =陣列(...)''到$圖像=陣列(...)''中get_images_gallery()' – Sean