我想要能够显示一个图像的总数中包含在一个专辑中(每个艺术家一张相册)的数目。例子:相册2的10。然后到下一个图像,我们将得到专辑3的10,等等。我可以通过使用一个函数get_count,然后在我的HTML页面上调用这个函数和一个foreach语句来获得总数。但是,我不知道如何编写代码来获得单个的nos。使用的代码:-
<?php
function get_count($artist_id) {
$artist_id = (int)$artist_id;
$count = array();
$count_query = mysql_query("
SELECT `image_album_id`, `artist_id`, COUNT(`image_album_id`) as `image_count`
FROM `album_images`
WHERE `artist_id`=$artist_id AND `member_id`=".$_SESSION['member_id']);
While ($count_row = mysql_fetch_assoc($count_query)) {
$count[] = array(
'id' => $count_row['image_album_id'],
'album' => $count_row['artist_id'],
'count' => $count_row['image_count']
);
}
return $count;
}
?>
<?php
$count = get_count($artist_id);
foreach ($count as $count){
echo '',$count['count'],'';
}
?>发布于 2012-10-11 03:24:47
问题在于对数组和标量可变量重用相同的变量名$count:
$count = get_count($artist_id);$count现在是一个数组。
foreach ($count as $count){但是$count现在变成了一个标量变量,消除了数组。
https://stackoverflow.com/questions/12831689
复制相似问题