简体   繁体   中英

Limit log data to only specific results

Hi so i have a touchscreen that allows guests and users learn more about our company. On the Main Homepage there are three areas guests/users and browse. These pages are Travel/Home.aspx, Menu/About/aspx, and Spotlight/Home.aspx. Each page also goes further in ie Page1 would give guests/users a list of current research being conducted and they can navigate further in by choosing the specific research project. The touchscreen also keeps a log of all the areas guests/users navigate to. I'm trying to filter this log so that I know which of the three main areas people visit the most. So far I can get my script to count and group ALL the logs like this:

 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 

But as you can see it displays ALL the logs. I want it to group all the logs under Page1, PAge2, and Page 3 and give me a total count. This is my code so far.

> <?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>";
>     ?>

Change your query to (1) sort by the count descending, and (2) limit to the top 3 (or as many as you'd like). Something like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM