Fix top 10 vote lists so they don't display the same version twice

This commit is contained in:
Alexander Nicolaysen Sørnes
2007-03-09 01:37:32 +00:00
committed by WineHQ
parent bf7daaa789
commit 71cba5e7c3

View File

@@ -269,15 +269,15 @@ function outputTopXRow($oRow)
} }
/* Output the rows for the Top-X tables on the main page */ /* Output the rows for the Top-X tables on the main page */
function outputTopXRowAppsFromRating($rating, $iNum_apps) function outputTopXRowAppsFromRating($sRating, $iNumApps)
{ {
/* clean the input values so we can continue to use query_appdb() */ /* clean the input values so we can continue to use query_appdb() */
$rating = mysql_real_escape_string($rating); $sRating = mysql_real_escape_string($sRating);
$iNum_apps = mysql_real_escape_string($iNum_apps); $iNumApps = mysql_real_escape_string($iNumApps);
/* list of appIds we've already output, so we don't output */ /* list of versionIds we've already output, so we don't output */
/* them again when filling in any empty spots in the list */ /* them again when filling in any empty spots in the list */
$appIdArray = array(); $aVersionId = array();
$sQuery = "SELECT appVotes.versionId, COUNT( appVotes.versionId ) AS c $sQuery = "SELECT appVotes.versionId, COUNT( appVotes.versionId ) AS c
FROM appVotes, appVersion FROM appVotes, appVersion
@@ -286,38 +286,37 @@ function outputTopXRowAppsFromRating($rating, $iNum_apps)
GROUP BY appVotes.versionId GROUP BY appVotes.versionId
ORDER BY c DESC ORDER BY c DESC
LIMIT ?"; LIMIT ?";
$hResult = query_parameters($sQuery, $rating, $iNum_apps); $hResult = query_parameters($sQuery, $sRating, $iNumApps);
$iNum_apps-=mysql_num_rows($hResult); /* take away the rows we are outputting here */ $iNumApps -= mysql_num_rows($hResult); /* take away the rows we are outputting here */
while($oRow = mysql_fetch_object($hResult)) while($oRow = mysql_fetch_object($hResult))
{ {
array_push($appIdArray, $oRow->appId); /* keep track of the apps we've already output */ /* keep track of the apps we've already output */
$aVersionId[] = $oRow->versionId;
outputTopXRow($oRow); outputTopXRow($oRow);
} }
/* if we have no more app entries we should stop now and save ourselves a query */ /* if we have no more app entries we should stop now and save ourselves a query */
if(!$iNum_apps) return; if(!$iNumApps) return;
/* if we have any empty spots in the list, get these from applications with images */ /* if we have any empty spots in the list, get these from applications with images */
$sQuery = "SELECT DISTINCT appVersion.versionId $sQuery = "SELECT DISTINCT appVersion.versionId
FROM appVersion, appData FROM appVersion, appData
WHERE appVersion.maintainer_rating = '$rating' WHERE appVersion.maintainer_rating = '$sRating'
AND appVersion.versionId = appData.versionId AND appVersion.versionId = appData.versionId
AND appData.type = 'image' AND appData.type = 'image'
AND appData.queued = 'false'"; AND appData.queued = 'false'";
/* make sure we exclude any apps we've already output */ /* make sure we exclude any apps we've already output */
foreach($appIdArray as $key=>$value) foreach($aVersionId as $key=>$value)
$sQuery.="AND appVersion.versionId != '".$value."' "; $sQuery.="AND appVersion.versionId != '".$value."' ";
$sQuery.=" LIMIT $iNum_apps"; $sQuery .= " LIMIT $iNumApps";
/* get the list that will fill the empty spots */ /* get the list that will fill the empty spots */
$hResult = query_appdb($sQuery); $hResult = query_appdb($sQuery);
while($oRow = mysql_fetch_object($hResult)) while($oRow = mysql_fetch_object($hResult))
{
outputTopXRow($oRow); outputTopXRow($oRow);
} }
}
/* return true if this word is in the list of words to ignore */ /* return true if this word is in the list of words to ignore */
function isIgnoredWord($sWord) function isIgnoredWord($sWord)