Good Morning,

I am working on a hockey pool site and am trying to build a standings page. You can see my output here

http://www.cornwallfantasyhockey.com/cfhl/standings2/

I would like to be able to write code that will sort the PTS column in descending order, however the PTS value in each row is a calculated value based on other calculations. Is this possible?

I have define the values as $PTS_xmen, $PTS_bull, $PTS_high, $PTS_ice.

Any help would be appreciated.
Cheers,
Chris

Show your query.

I have made progress but here is what I am struggling with now. I am trying to assign values within a loop but it keeps echo'ing the value for the first Row and not the individual ones. It is my syntax that is the problem within the loop. I have tried many variations...here is one:

if ($row['PF_wk1'] > $row['PA_wk1']) 
{
$W_wk1="1";
}
if ($row['PF_wk2'] > $row['PA_wk2']) 
{
$W_wk2="1";
}
echo $W_wk1+$W_wk2;

Any help would be appreciated.

You're not showing enough information. The code you posted is correct, but the context may not be.

You're not showing enough information. The code you posted is correct, but the context may not be.

Here is the whole chunk of code It is lines 52-66 that I am struggling with. It is not returning a unique value for each of the 4 teams.

<?php


$GETQ="SELECT * FROM `standings1011_cfhl` WHERE Team = 'xmen' OR Team = 'bull' OR Team = 'high' OR Team = 'ice'

ORDER BY
`PTS` DESC";

$result = mysql_query($GETQ)
or die(mysql_error());    
 // Table Header
echo "<table width='570' border='1' cellspacing='0' cellpadding='0' bgcolor='ffffff'>";
echo "
<tr><td colspan='12' align='center' bgcolor='000000'><font face='arial' size='4' color='ff0000'><b><i>Gretzky Division</i></b>
<tr> 
<td width='20' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>WK</b></td>
<td width='150' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>Opponent</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>GP</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>W</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>L</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>T</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>PF</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>PA</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>PTS</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>PPG</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>PCT</b></td>
<td width='40' align='center' bgcolor='cccccc'><font face='arial' size='2' color='000000'><b>+/-</b></td>
</tr>";


// keeps getting the next row until there are no more to get


$n=1;
while($row = mysql_fetch_assoc( $result )) {

	// Print out the contents of each row into a table
	
//rank	
echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>"; 
echo "".$n++;

 // Team
echo "</td><td width='150' bgcolor='FFFFFF'><a href='/cfhl/icedogs/1011_results.php'>";
echo "<img src='/images/bar_".$row['Team'].".jpg' width='150' height='19' border='0'>";

 // GP
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";
$ttl_GP=$row['GP_wk1']+$row['GP_wk2']+$row['GP_wk3']+$row['GP_wk4']+$row['GP_wk5']+$row['GP_wk6']+$row['GP_wk7']+$row['GP_wk8']+$row['GP_wk9']+$row['GP_wk10']+$row['GP_wk11']+$row['GP_wk12']+$row['GP_wk13']+$row['GP_wk14']+$row['GP_wk15']+$row['GP_wk16']+$row['GP_wk17']+$row['GP_wk18']+$row['GP_wk19']+$row['GP_wk20']+$row['GP_wk21']+$row['GP_wk22']+$row['GP_wk23']+$row['GP_wk24']+$row['GP_wk25']+$row['GP_wk26'];
echo $ttl_GP;

 // W
 echo "<td width='40' bgcolor='FFFFFF' align='center'><font face='arial' size='2' color='000000'>";

if ($row['PF_wk1'] > $row['PA_wk1']){

$W_wk1="1";
}

if ($row['PF_wk2'] > $row['PA_wk2']){

$W_wk2="1";
}


echo $W_wk1+$W_wk2;



 // L
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";

 // T
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";

 // PF
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";
$ttl_PF=$row['PF_wk1']+$row['PF_wk2']+$row['PF_wk3']+$row['PF_wk4']+$row['PF_wk5']+$row['PF_wk6']+$row['PF_wk7']+$row['PF_wk8']+$row['PF_wk9']+$row['PF_wk10']+$row['PF_wk11']+$row['PF_wk12']+$row['PF_wk13']+$row['PF_wk14']+$row['PF_wk15']+$row['PF_wk16']+$row['PF_wk17']+$row['PF_wk18']+$row['PF_wk19']+$row['PF_wk20']+$row['PF_wk21']+$row['PF_wk22']+$row['PF_wk23']+$row['PF_wk24']+$row['PF_wk25']+$row['PF_wk26'];
echo $ttl_PF;

 // PA
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";
$ttl_PA=$row['PA_wk1']+$row['PA_wk2']+$row['PA_wk3']+$row['PA_wk4']+$row['PA_wk5']+$row['PA_wk6']+$row['PA_wk7']+$row['PA_wk8']+$row['PA_wk9']+$row['PA_wk10']+$row['PA_wk11']+$row['PA_wk12']+$row['PA_wk13']+$row['PA_wk14']+$row['PA_wk15']+$row['PA_wk16']+$row['PA_wk17']+$row['PA_wk18']+$row['PA_wk19']+$row['PA_wk20']+$row['PA_wk21']+$row['PA_wk22']+$row['PA_wk23']+$row['PA_wk24']+$row['PA_wk25']+$row['PA_wk26'];
echo $ttl_PA;

 // PTS
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";

 // PPG
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";
 

 // PCT
echo "<td width='40' bgcolor='FFFFFF' align='center'><font face='arial' size='2' color='000000'>";


 // +/-
echo "<td width='40' bgcolor='FFFFFF' align='center'><font face='arial' size='2' color='000000'>";
echo number_format($ttl_PF - $ttl_PA);


}





?>

If both if's are false, then your variables do not have a value, try changing it to:

if ($row['PF_wk1'] > $row['PA_wk1'])
  $W_wk1 = 1;
else
  $W_wk1 = 0;
 
if ($row['PF_wk2'] > $row['PA_wk2'])
  $W_wk2 = 1;
else
  $W_wk2 = 0;
 
echo $W_wk1 + $W_wk2;
commented: thanks ! +1

AWESOME!!! THANKS SO MUCH! I have been tinkering with this all afternoon!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.