// Includes the Constants
include("cons.php");
// Get VARS
$status= $_POST['status'];
$error = $_GET['error'];
$err = $_GET['err'];
$userid = $_GET['userid'];
$winner = $_GET['winner'];
//FUNCTIONS
function subval_sort($a,$subkey) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
arsort($b);
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return $c;
}
function percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 2);
return $count;
}
//END FUNCTIONS
//Read DB
$query = mysql_query ("Select hotid, Name, Rank1st, link FROM hottie") or die(mysql_error());
//$result =mysql_fetch_assoc($query);
while ($row = mysql_fetch_array($query, MYSQL_BOTH)) {
$hotties[]= array('Name' => $row[Name], 'Rank1st' => $row[Rank1st], 'hotid' => $row[hotid], 'link' => $row[link]);
}
//SORTS hotties with most ranked first
$hotties = subval_sort($hotties,'Rank1st');
//GETS TOTAL VOTES
$totalvotes=0;
foreach ($hotties as $key => $val) {
//echo $val[Rank1st];
$totalvotes= $totalvotes + $val[Rank1st];
}
//calcs top 5 percentages
$onepercent = percent($hotties[0][Rank1st], $totalvotes);
$twopercent = percent($hotties[1][Rank1st], $totalvotes);
$threepercent = percent($hotties[2][Rank1st], $totalvotes);
$fourpercent = percent($hotties[3][Rank1st], $totalvotes);
$fivepercent = percent($hotties[4][Rank1st], $totalvotes);
// END READ DB
include("longheader.php");
?>
with "; $onepercent= substr ($onepercent ,0 , -3); echo $onepercent; echo "% of the total picks"; ?>
with "; $twopercent= substr ($twopercent ,0 , -3); echo $twopercent; echo "% of the total picks"; ?>
with "; $onepercent= substr ($onepercent ,0 , -3); echo $onepercent; echo "% of the total picks"; ?>
with "; $twopercent= substr ($twopercent ,0 , -3); echo $twopercent; echo "% of the total picks"; ?>
with "; $threepercent= substr ($threepercent ,0 , -3); echo $threepercent; echo "% of the total picks"; ?>