Forum Moderators: coopster
Order By totyrtips Desc
then by $rdmargintotlb1
here is the code below what Im trying to get to work..
<?php
if($_GET['action'] == 'rdleaderboard'){
// Start Multipage
$page = (isset($page) && is_numeric($page))? (int) $page : 1; // Validation
$perpage = "100"; // Entries to show per page. If set to $ppp it will depend on the users Posts Per Page setting
if ($page) {
$start_limit = ($page-1) * $perpage;
} else {
$start_limit = 0;
$page = 1;
}
// Multipage query
$query = $db->query("Select Count(tipping.uid) From tipping");
$total = $db->result($query, 0);
$mpurl = "$PHP_SELF?action=$action&rd=$rd"; // the name of the current file, you can also include variables!
$multip = multi($total, $perpage, $page, $mpurl);
$pages = "$multip";
// End Multipage
$result = mysql_query("Select Count(tipping.tip_id) AS totyrtips, tpfp_members.username, tpfp_members.uid From tipping Inner Join testfixture ON tipping.testfixture_id = testfixture.testfixture_id Inner Join tpfp_members ON tipping.uid = tpfp_members.uid Where tipping.tip = testfixture.winner AND tipping.league_id = '6' AND tipping.season = '$current_season' AND tipping.gamedesc_id = '$rd' Group By tipping.uid Order By totyrtips Desc LIMIT $start_limit, $perpage");
$num = mysql_num_rows($result);
if($num!= 0) {
echo "<table width=100% class=mediumtxt border=$borderwidth style=border-collapse:collapse cellpadding=$tablespace bordercolor=$bordercolor>";
echo "<tr><td class=category><font color=$cattext><strong>Tipping $menugamedesc Leaderboard</strong></td></tr>";
echo "<table width=100% class=mediumtxt border=$borderwidth style=border-collapse:collapse cellpadding=$tablespace bordercolor=$bordercolor>";
echo "<tr><td width=50% class=header><strong>Name</strong></td><td width=25% class=header><center><strong>Tips</strong></center></td><td width=25% class=header><center><strong>Margin</strong></center></td></tr>";
$alternate = "1";
while ($row = mysql_fetch_array($result))
{
$result1 = mysql_query("Select testfixture.margin AS fixturemargintotlb1, tipping.margin AS tipmargintotlb1, testfixture.winner as winnertotlb1, tipping.tip as tippedtotlb1 From tipping Inner Join testfixture ON testfixture.testfixture_id = tipping.testfixture_id Where tipping.season = '$current_season' AND tipping.league_id = '6' AND tipping.gamedesc_id = '$rd' AND tipping.game_id = '1' AND `uid` = '".$row['uid']."'");
$row1 = mysql_fetch_assoc($result1);
$winnertotlb1 = $row1["winnertotlb1"];
$tippedtotlb1 = $row1["tippedtotlb1"];
$fixturemargintotlb1 = $row1["fixturemargintotlb1"];
$tipmargintotlb1 = $row1["tipmargintotlb1"];
if ($tippedtotlb1 == $winnertotlb1 && $tipmargintotlb1 == $fixturemargintotlb1 ) {
$rdmargintotlb1 = '0';
} else {
// Nothing
}
if ($tippedtotlb1 == $winnertotlb1 && $tipmargintotlb1 < $fixturemargintotlb1) {
$rdmargintotlb1 = $fixturemargintotlb1 - $tipmargintotlb1;
} else {
// Nothing
}
if ($tippedtotlb1 == $winnertotlb1 && $tipmargintotlb1 > $fixturemargintotlb1) {
$rdmargintotlb1 = $tipmargintotlb1 - $fixturemargintotlb1;
} else {
// Nothing
}
if ($tippedtotlb1 <> $winnertotlb1) {
$rdmargintotlb1 = $fixturemargintotlb1 + $tipmargintotlb1;
} else {
// Nothing
}
$username = $row["username"];
$totyrtips = $row["totyrtips"];
if ($alternate == "1") {
$color = "$altbg1";
$alternate = "2";
}
else {
$color = "$altbg2";
$alternate = "1";
}
echo "<tr bgcolor=$color><td width=50%>$username</td><td width=25%><center>$totyrtips</center></td><td width=25%><center>$rdmargintotlb1</center></td></tr>";
}
echo "<tr bgcolor=$altbg2><td colspan=3>$pages</td></tr>";
echo "</table>";
} else {
echo "<table width=100% class=mediumtxt border=$borderwidth style=border-collapse:collapse cellpadding=$tablespace bordercolor=$bordercolor>";
echo "<tr><td class=category><font color=$cattext><strong>Tipping $menugamedesc Leaderboard</strong></td></tr>";
echo "<table width=100% class=mediumtxt border=$borderwidth style=border-collapse:collapse cellpadding=$tablespace bordercolor=$bordercolor>";
echo "<tr><td width=50% class=header><strong>Name</strong></td><td width=25% class=header><center><strong>Tips</strong></center></td><td width=25% class=header><center><strong>Total Margin</strong></center></td></tr>";
echo "<tr bgcolor=$color><td width=50%> </td><td width=25%><center> </center></td><td width=25%><center> </center></td></tr>";
echo "</table>";
}
}
?>
Can you please elaborate on what you are actually trying to accomplish with $rdmargintotlb1? What do you mean by sorting by it?
regarding code dumps in this forum [webmasterworld.com]...
perhaps you should post just the relevant snippet of code when you clarify your problem description.
What happens is a member enters a margin for a game each round then after the game result tippers are ranked by how many tips they got right then secondly by their round margin..
If you tip the winning Team and their exact winning margin, your 'Round Margin' will equal 0 points/goals (like golf, lower is better).
If you pick the winning team, but not the winning margin, your 'Round Margin' will equal the difference between the actual game margin and the margin you tipped.
If you tip the losing Team, your 'Round Margin' will equal the points/goals difference of the actual game margin PLUS the margin you tipped.
so what I was basically trying to do is get each tippers margin and rank them accordingly..
$mpurl = "$PHP_SELF?action=$action&rd=$rd"; // the name of the current file, you can also include variables!
$_SERVER[’PHP_SELF’]
http://www.example.com/example/ => /example/index.php
http://www.example.com/example/index.php => /example/index.php
http://www.example.com/example/index.php?a=test => /example/index.php
http://www.example.com/example/index.php/dir/test => /dir/test
$_SERVER[’SCRIPT_NAME’]
http://www.example.com/example/ => /example/index.php
http://www.example.com/example/index.php => /example/index.php
http://www.example.com/example/index.php?a=test => /example/index.php
http://www.example.com/example/index.php/dir/test => /example/index.php