将日志数据限制为仅特定结果

时间:2011-04-08 20:35:55

标签: php mysql limit

大家好,我有一个触摸屏,可以让客人和用户了解我们公司的更多信息。在主页面上有三个区域的客人/用户和浏览。这些页面是Travel / Home.aspx,Menu / About / aspx和Spotlight / Home.aspx。每个页面也更进一步,即Page1将为客人/用户提供当前正在进行的研究的列表,并且他们可以通过选择特定的研究项目进一步导航。触摸屏还会记录客户/用户导航到的所有区域。我正在尝试过滤此日志,以便我知道人们访问最多的三个主要区域中的哪一个。到目前为止,我可以让我的脚本计算并对所有日志进行分组:

Top 5 Destinations: 12 http://www..org/scraper.php?link=/Home.aspx
Top 5 Destinations: 5 http://www..org/scraper.php?link=/Menu/About.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/Posters/Home.aspx
Top 5 Destinations: 3 http://www..org/scraper.php?link=/ResearchAreas/Home.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/ResearchAreas/Nutrients.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/ResearchAreas/Nutrients/IdentificationOfNutrientSources.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/ResearchAreas/Nutrients/IdentificationOfNutrientSources/AtmosphericDeposition.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/ResearchAreas/Nutrients/IdentificationOfNutrientSources/AtmosphericDeposition/AtmosphericNutrientDeposition.aspx
Top 5 Destinations: 2 http://www..org/scraper.php?link=/ResearchAreas/RegionalMonitoring.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/ResearchAreas/RegionalMonitoring/BightRegionalMonitoring.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/Spotlight/Home.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/Staff/Home.aspx
Top 5 Destinations: 3 http://www..org/scraper.php?link=/Travel/Home.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/Travel/LosAngelesDepartures.aspx
Top 5 Destinations: 1 http://www..org/scraper.php?link=/Travel/Traffic.aspx

但是你可以看到它显示所有日志。我希望它将Page1,PAge2和Page 3下的所有日志分组,并给我一个总计数。到目前为止,这是我的代码。

> <?php
>     
>     #### mysql connection #####
>     $db = mysql_connect("_","guest","_");
>     mysql_select_db(networkr) or die("Couldn't select the database");
>     echo "<table>";
>     $query = "SELECT count(*),uri FROM logs GROUP BY uri";
>     $result = mysql_query($query) or die(mysql_error());
>     while($row = mysql_fetch_array($result)){
>       echo "Main Hits:  ". $row['0'] ."   ". $row['1'] ."";
>       echo "<br />";
>     }
>     echo "</table>";
>     ?>

1 个答案:

答案 0 :(得分:0)

将您的查询更改为(1)按计数降序排序,(2)将限制排在前3位(或根据您的喜好)。像下面的东西

$query = "SELECT count(*),uri FROM logs GROUP BY uri ORDER BY count(*) DESC LIMIT 3";