Php Mysql计数,使用join和where子句递减,两个表,限制?

Php Mysql计数,使用join和where子句递减,两个表,限制?,php,mysql,sql,mysqli,Php,Mysql,Sql,Mysqli,在这里,我实现了两个表(pages,pagestatistics)。我需要这些表中使用join的最后五条记录的结果,还需要第二个表(pagestatistics)中的cID计数字段,我需要计数结果以降序显示 注意:主id是cID !![网页统计][1]!![页数][2] <?php $recentpageviews =mysql_query("SELECT Distinct(cID) FROM `pagestatistics` order by `pstID` desc lim

在这里,我实现了两个表(pages,pagestatistics)。我需要这些表中使用join的最后五条记录的结果,还需要第二个表(pagestatistics)中的cID计数字段,我需要计数结果以降序显示

注意:主id是cID

!![网页统计][1]!![页数][2]

   <?php 
$recentpageviews =mysql_query("SELECT  Distinct(cID) FROM `pagestatistics`  order by `pstID` desc limit 0,5");
$downloads=mysql_num_rows($recentpageviews);
$k=1;
$cid="";
      while($views_values=mysql_fetch_array($recentpageviews))
{       
        $cid.=",".$views_values['cID'];
$k++;}
}
$explode =explode(",",$cid);
for($i=1;$i<count($explode);$i++)
{
$sql=mysql_query("select  Distinct(a.cID),count(a.cID) as clicks,b.cFilename,a.date from pagestatistics as a left join pages as b on a.cID=b.cID where a.cID='".$explode[$i]."' order by a.cID desc");
$res=mysql_fetch_array($sql);

?>
 <tr>

        <td class='ccm-site-statistics-downloads-title'><?php echo $res['cFilename'];?></td>
        <td class='ccm-site-statistics-downloads-title'><?php echo $res['clicks'];?></td>
       <td class='ccm-site-statistics-downloads-title'><?php echo $res['date'];?></td>
    </tr>

<?php }?>

您可以通过这种方式完成,只需在
order by
子句中使用您的
计数
分隔,

$sql=mysql_query("select  Distinct(a.cID),count(a.cID) as clicks,b.cFilename,a.date
 from pagestatistics as a left join pages as b on a.cID=b.cID 
where a.cID='".$explode[$i]."' order by a.cID,clicks desc");

你想在什么基础上继承这个记录。嗨@Breaknheartღ - 我需要显示最后五条记录和页面点击值的计数(这里页面点击值是cID,cID是PageStatistics表的fieldname)。目前,我显示了最后五个值以及该值的计数。在那之后,我需要重新排列计数值在下降arderI检查,但它不工作,给一些其他的解决方案。