Good Morning,
I am building a hockey pool site and here is some background on my problem. Our league allows each player to be drafted twice. So we have given each player an A or B listing (ie Sydney Crosby A or Sydney Crosby B). In my database, I have two columns called CFHL_A and CFHL_B and in this column I put in the abbreviation for each Fantasy Team that the player belongs too. Then when I do SELECT, I can populate the various teams by search by the abbreviation. No issues there.
In some player's cases, only one of the two have been drafted. So the player who is not drafted is a Free Agent and as such I list them as FREE in my database. For exmaple, D Luke Schenn was drafted by the Habs only. So his listing is CFHL_A = 'HABS' and CFHL_B = 'FREE'.
I am trying to create a page that lists all the available FREE AGENTS by position. So, in this example Luke Schenn B should be listed in the QUERY result. No problem with any player that is on one team and a free agent on the other.
In some cases, a player has not been drafted at all and is listed as FREE-FREE. So, in this case I want the player to be listed in the Free Agent list - twice. Once as the A and once as the B. An example of this would be D P.K. Subban. You can see my progress here:
http://www.cornwallfantasyhockey.com/cfhl/free_agents_D/
SO HERE IS MY PROBLEM: I can get the FREE-FREE guys to list twice in my output table, but I cannot get the A or the B to show properly. Here is my code:
<?php
$result = mysql_query("SELECT * FROM playerdb where (CFHL_A = 'FREE') AND POS= 'D' UNION ALL SELECT * FROM playerdb where (CFHL_B = 'FREE') AND POS= 'D' order by PTS0910 DESC, GP0910 ASC, TEAM ASC")
or die(mysql_error());
echo "<table width='350' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
echo "<tr>
<td width='15' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>#</b></td>
<td width='20' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>POS</b></td>
<td width='170' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>PLAYER</b></td>
<td width='10' bgcolor='000000' align='center'><font face='arial' size='1' color='000000'><b>.</b></td>
<td width='30' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>TEAM</b></td>
<td width='20' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>AGE</b></td>
<td width='20' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>GP</b></td>
<td width='20' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>PTS</b></td>
<td width='30' bgcolor='000000' align='center'><font face='arial' size='1' color='ffffff'><b>PPG</b></td>
</tr>";
// keeps getting the next row until there are no more to get
$n=1;
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>";
echo "".$n++;
echo "</td><td width='15' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>";
echo $row['Pos'];
echo "</td><td width='170' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>";
echo $row['Last'];
echo ", ";
echo $row['First'];
echo "</td><td width='10' bgcolor='ffffff' align='center'><font face='arial' size='1' color='000000'>";
if (($row['CFHL_A']=="FREE") and ($row['CFHL_B']!="FREE")) echo "A";
if (($row['CFHL_A']!="FREE") and ($row['CFHL_B']=="FREE")) echo "B";
echo "</td><td width='30' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>";
echo $row['Team'];
echo "</td><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>";
echo calculateAge($row['BDay']);
echo "</td><td width='20' bgcolor='CCCCCC' align='center'><font face='arial' size='2' color='000000'><b>";
echo $row['GP0910'];
echo "</td><td width='20' bgcolor='CCCCCC' align='center'><font face='arial' size='2' color='000000'><b>";
echo $row['PTS0910'];
echo "</td><td width='30' bgcolor='CCCCCC' align='center'><font face='arial' size='2' color='000000'><b>";
echo number_format($row['PTS0910']/$row['GP0910'],2);
error_reporting (E_ERROR);
echo "</td></tr>";
}
echo "</table>";
?>
My challenge is with the coding in and around line 38 and 39. I have tried adding the following, but it hasnt worked: (it gives me AB)
if (($row['CFHL_A']=="FREE") and ($row['CFHL_B']!="FREE")) echo "A";
if (($row['CFHL_A']!="FREE") and ($row['CFHL_B']=="FREE")) echo "B";
if ((($row['CFHL_A']=="FREE") and ($row['CFHL_B']=="FREE"))) and ($row['CFHL_A']=="FREE") echo "A";
if ((($row['CFHL_A']=="FREE") and ($row['CFHL_B']=="FREE"))) and ($row['CFHL_B']=="FREE") echo "B";
I have tried many things and am still struggling. Any help would be greatly appreciated!
Cheers,
Chris