Forum Moderators: coopster

Message Too Old, No Replies

sorting problem?

         

mark_g

12:26 pm on Jan 18, 2008 (gmt 0)

10+ Year Member


Im having trouble sorting the record display and to keep it simple all I want to do is sort by

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%>&nbsp;</td><td width=25%><center>&nbsp;</center></td><td width=25%><center>&nbsp;</center></td></tr>";
echo "</table>";
}
}
?>

eelixduppy

12:52 am on Jan 21, 2008 (gmt 0)



Welcome to WebmasterWorld!

Can you please elaborate on what you are actually trying to accomplish with $rdmargintotlb1? What do you mean by sorting by it?

phranque

3:59 am on Jan 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], mark_g!

regarding code dumps in this forum [webmasterworld.com]...

perhaps you should post just the relevant snippet of code when you clarify your problem description.

mark_g

7:51 am on Jan 21, 2008 (gmt 0)

10+ Year Member



$rdmargintotlb1 is to actually display a members tipping margin for a tipping competition.

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..

PHP_Chimp

4:13 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a lot of code up there, so I stopped reading when I got to -
$mpurl = "$PHP_SELF?action=$action&rd=$rd"; // the name of the current file, you can also include variables!

Am I correct in assuming that you have register globals enabled?
As $PHP_SELF should be $_SERVER['PHP_SELF']. I say should be as the short form is turned off by default in later versions of php, and you need to be very careful with your scripts if you choose to have the short form enabled.
Have a read of register globals security [uk.php.net].
You may also want to change PHP_SELF to $_SERVER['SCRIPT_NAME'], as there are some issues with PHP_SELF. Have a look at the bold bit below and see the problem.


$_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