diff --git a/include/util.php b/include/util.php
index 857601f..b5e8ed5 100644
--- a/include/util.php
+++ b/include/util.php
@@ -253,4 +253,52 @@ function lookupVendorName($vendorId)
return $vendor->vendorName;
}
-?>
+/* Output the rows for the Top-X tables on the main page */
+function outputTopXRowAppsFromRating($rating, $num_apps)
+{
+ $sQuery = "SELECT appVotes.appId AS appId, COUNT( appVotes.appId ) AS c
+ FROM appVotes, appVersion
+ WHERE appVersion.maintainer_rating = '$rating'
+ AND appVersion.appId = appVotes.appId
+ GROUP BY appVotes.appId
+ ORDER BY c DESC
+ LIMIT $num_apps";
+ $hResult = query_appdb($sQuery);
+ $num_apps-=mysql_num_rows($hResult); /* take away the rows we are outputting here */
+ while($oRow = mysql_fetch_object($hResult))
+ {
+ $oApp = new Application($oRow->appId);
+ // image
+ $img = get_screenshot_img($oRow->appId);
+ echo '
+
+ | '.$oApp->sName.' |
+ '.trim_description($oApp->sDescription).' |
+ '.$img.' |
+
';
+ }
+
+ /* if we have any empty spots in the list, get these from applications with images */
+ $sQuery = "SELECT DISTINCT appVersion.appId as appId
+ FROM appVersion, appData
+ WHERE appVersion.maintainer_rating = '$rating'
+ AND appVersion.versionId = appData.versionId
+ AND appData.type = 'image'
+ AND appData.queued = 'false'
+ LIMIT $num_apps";
+ $hResult = query_appdb($sQuery);
+ while($oRow = mysql_fetch_object($hResult))
+ {
+ $oApp = new Application($oRow->appId);
+ // image
+ $img = get_screenshot_img($oRow->appId);
+ echo '
+
+ | '.$oApp->sName.' |
+ '.trim_description($oApp->sDescription).' |
+ '.$img.' |
+
';
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index ff2ccab..8d1da3e 100644
--- a/index.php
+++ b/index.php
@@ -70,10 +70,17 @@ If you have screenshots or links to contribute, please browse the database and u
$voteAppId = $ob->appId;
$voteAppName = $ob->appName;
-
- echo "There are $numApps applications currently in the database with\n";
- echo "$voteAppName being the\n";
- echo "top voted application.\n";
+ /* don't mention the top application if there are no votes yet */
+ if($voteAppId != "")
+ {
+ echo "There are $numApps applications currently in the database with\n";
+ echo "$voteAppName being the\n";
+ echo "top voted application.\n";
+ } else
+ {
+ echo "There are $numApps applications currently in the database, please\n";
+ echo "vote for your favorite application.\n";
+ }
?>
@@ -89,26 +96,7 @@ If you have screenshots or links to contribute, please browse the database and u
Application | Description | Screenshot |
appId);
- // image
- $img = get_screenshot_img($oRow->appId);
- echo '
-
- | '.$oApp->sName.' |
- '.trim_description($oApp->sDescription).' |
- '.$img.' |
-
';
-}
+ outputTopXRowAppsFromRating('Gold', 10);
?>
@@ -119,26 +107,7 @@ while($oRow = mysql_fetch_object($hResult))
Application | Description | Screenshot |
appId);
- // image
- $img = get_screenshot_img($oRow->appId);
- echo '
-
- | '.$oApp->sName.' |
- '.trim_description($oApp->sDescription).' |
- '.$img.' |
-
';
-}
+ outputTopXRowAppsFromRating('Silver', 10);
?>