我如何根据用户ID计算每张专辑的上传图片..我已经完成了这个但是不行......有些帮助表示赞赏。我是新学员!
这就是我所拥有的:
Album db: |albumid|name|image|uid| <- user id
Gallery db: |galleryid|albumid|name|images|uid|
代码
$sql = "
SELECT COUNT(userid)
FROM tbl_gallery
where userid = 1
";
$rs_result = mysql_query($sql,$con);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
echo $total_records;
$sql = "SELECT * FROM tbl_album where userid = 1 ORDER BY albumid";
$rs_result = mysql_query($sql,$con);
####### Fetch Results From Table ########
while ($row = mysql_fetch_assoc($rs_result))
{
$aimage=$row['image'];
$aid=$row['albumid'];
$aname=$row['name'];
<div class="pic">
<?php
echo "<a href='includes/galeriefoto/gallery.php?id=1'> <img src='includes/galeriefoto/admin/acatch/$aimage' class='thumbimg' alt='Pic' alt='$aname'>";
?>
<span class='pic-caption'>
<center><p style='color:#000;font-size:24px'><?php echo $aname;?> (<?php echo $total_records;?>)</p></center>
</span></a>
</div>
<?php } ?>
答案 0 :(得分:0)
如果只是计算相册中的图像数量,以下内容就足以满足您的查询要求:
SELECT uid, albumid, COUNT(galleryid) as num_upload_images
FROM tbl_gallery
GROUP BY uid, albumid
这导致以下可能的输出:
[0] => [
uid => 1,
albumid => 1,
num_upload_images => 15
],
[1] => [
uid => 1,
albumid => 2,
num_upload_images => 12
]