获取分类中的行数

cntegzs 2012-03-11 08:17:43
已知表:
分类表:type
内容表:list

其中:分类表type typecode = 内容表list catid

循环type的分类,同时循环list中与分类对应的内容

问:在分类表循环中统计内容表中对应的内容数量的语句怎么写?
...全文
67 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cntegzs 2012-03-12
  • 打赏
  • 举报
回复
谢谢上面的答复,可能没表达清楚,两个表已经在循环中的统计:
查询贴出来:
其中:分类表type typecode = 内容表list catid

<?php
//分类表
$sql="select * from ".$BIAOTOU."type order by sort desc limit 0,15";
$rs_type=mysql_query($sql);

//内容表
$sql="select * from ".$BIAOTOU."list where end_time >='".date('Y-m-d')."' order by id desc";
$rs_list=mysql_query($sql);
$i=0;
while ($row2 = mysql_fetch_array($rs_list)){
$allmalllist[$i]['id']= $row2['id'];
$allmalllist[$i]['catid']= $row2['catid'];
$allmalllist[$i]['name']= $row2['name'];
$allmalllist[$i]['fan']= $row2['fan'];
$allmalllist[$i]['logo']= $row2['logo'];
$i++;
}
?>



<?php
while ($row1 = mysql_fetch_array($rs_type)) {?>
<?=$row1['typename']?>(这里统计该分类的内容量)
<ul>
<?php
$i=0;
foreach ($allmalllist as $row3){
if($row3["catid"]==$row1["typecode"]&&$i10){
echo "<li>".$row3['name']."</li>";
$i++;
}
}
?>
</ul>
<?php }?>
wwwwb 2012-03-12
  • 打赏
  • 举报
回复
select A.typecode,count(*) from type a inner join list B
on A.typecode = B.catid group by A.typecode
cntegzs 2012-03-12
  • 打赏
  • 举报
回复
谢谢5楼的高手,搞定了
Rotel-刘志东 2012-03-12
  • 打赏
  • 举报
回复
select A.typecode,count(*) from type a
inner join list B
on A.typecode = B.catid
group by A.typecode
一起混吧 2012-03-12
  • 打赏
  • 举报
回复
加上下面一段:
//查询出每个分类下面的数量。
$result=mysql_query("select catid,count(*) as num
from list
group by catid");
while($row3=mysql_fetch_array($result)){
$arr[$row3['catid']]=$row3['num'];
}

while ($row1 = mysql_fetch_array($rs_type)) {?>
<?=$row1['typename']?> <?=$arr[$row1['typecode']]?>
<ul>
ACMAIN_CHM 2012-03-11
  • 打赏
  • 举报
回复
select catid,count(*)
from list
group by catid
rucypli 2012-03-11
  • 打赏
  • 举报
回复
select A.typecode,count(*)
from type A,list B
where A.typecode = B.catid
group by A.typecode

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧