select A.typecode,count(*) from type A,list B where A.typecode = B.catid group by A.typecode
select catid,count(*) from list group by catid
select A.typecode,count(*) from type a inner join list B on A.typecode = B.catid group by A.typecode
谢谢上面的答复,可能没表达清楚,两个表已经在循环中的统计: 查询贴出来: 其中:分类表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 }?>
加上下面一段: //查询出每个分类下面的数量。 $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>
select A.typecode,count(*) from type a inner join list B on A.typecode = B.catid group by A.typecode
from type A,list B
where A.typecode = B.catid
group by A.typecode
from list
group by catid
on A.typecode = B.catid group by A.typecode
查询贴出来:
其中:分类表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 }?>
//查询出每个分类下面的数量。
$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>
inner join list B
on A.typecode = B.catid
group by A.typecode