From 471f673a01f0c8f1d59e8c78a46c63ac30f7c504 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 9 Nov 2004 22:31:15 +0000 Subject: [PATCH] Add the ability to choose the number of top apps you want and to drill down into sections --- votestats.php | 151 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 6 deletions(-) diff --git a/votestats.php b/votestats.php index 2a19fd9..573253e 100644 --- a/votestats.php +++ b/votestats.php @@ -2,15 +2,146 @@ include("path.php"); include(BASE."include/"."incl.php"); +require(BASE."include/"."category.php"); -apidb_header("Vote Stats - Top 25 Applications"); +/* default to 25 apps, main categories */ +$topNumber = 25; +$categoryId = "any"; /* default to all categories */ +/* process the post variables to override the default settings */ +if($HTTP_POST_VARS) +{ + if(isset($_POST['topNumber'])) $topNumber = $_POST['topNumber']; + if(isset($_POST['categoryId'])) $categoryId = $_POST['categoryId']; +} -$voteQuery = "SELECT appVotes.appId, appName, count(userId) as count ". - "FROM appVotes, appFamily ". - "WHERE appVotes.appId = appFamily.appId ". - "GROUP BY appId ORDER BY count DESC LIMIT 25"; +apidb_header("Vote Stats - Top $topNumber Applications"); +/* display the selection for the top number of apps to view */ +echo "
"; +echo "Number of top apps to display:"; +echo ""; + +/* list sub categories */ +if($categoryId == "any") + $catId = 0; +else + $catId = $categoryId; + +/******************************************************************/ +/* build an array of categories from the current category back up */ +/* the tree to the main category */ +$cat_array = Array(); +$cat_name_array = Array(); + +if($catId != 0) +{ + $currentCatId = $catId; + + do + { + $catQuery = "SELECT appCategory.catName, appCategory.catParent ". + "FROM appCategory WHERE appCategory.catId = '$currentCatId';"; + $result = mysql_query($catQuery); + + if($result) + { + $row = mysql_fetch_object($result); + $catParent = $row->catParent; + + array_push($cat_array, "$currentCatId"); + array_push($cat_name_array, "$row->catName"); + } + + $currentCatId = $catParent; + } while($currentCatId != 0); +} + +/*******************************************************************/ +/* add options for all of the categories that we are recursed into */ +echo "Section:"; +echo ""; + +echo ""; +echo "
"; + +echo "
"; +echo "
"; + +/***************************************************/ +/* build a list of the apps in the chosen category */ +if(strcasecmp($categoryId, "any") == 0) +{ + /* leave out the appFamily.catId = '$categoryId' */ + $voteQuery = "SELECT appVotes.appId, appName, count(userId) as count ". + "FROM appVotes, appFamily ". + "WHERE appVotes.appId = appFamily.appId ". + "GROUP BY appId ORDER BY count DESC LIMIT $topNumber"; +} else +{ + $voteQuery = "SELECT appVotes.appId, appName, count(userId) as count ". + "FROM appVotes, appFamily, appCategory ". + "WHERE appVotes.appId = appFamily.appId AND ". + "(appFamily.catId = '$categoryId' OR ". + "(appFamily.catId = appCategory.catId AND appCategory.catParent = '$categoryId')) ". + "GROUP BY appId ORDER BY count DESC LIMIT $topNumber"; +} $result = mysql_query($voteQuery); @@ -29,9 +160,17 @@ if($result) echo "$c. $link $row->count \n"; $c++; } + echo html_table_end(); echo html_frame_end(); - + + /* Make sure we tell the user here are no apps, otherwise they might */ + /* think that something went wrong with the server */ + if($c == 1) + { + echo "

No apps found in this category

"; + } + echo "
What does this screen mean?
\n"; }