I am having a couple of different problems with the same process.
Problem one: I can't figure out why I'm getting the values I am.
Problem two: I don't know if I'm using the proper process anyway.
This is a long post; trying to fit all info into it.
I want to create a list from which a player can select a team. Once they've selected that team they cannot select it again. So, I have to cross-check with their previous selections and remove those teams from their choices.
Here's what I thought was working. You'll note lots of "print" and "echo" statements. I'm trying to figure things out.
$AFC=array(00 => ' ',01 => 'Baltimore Ravens','Buffalo Bills','Cincinnati Bengals','Cleveland Browns','Denver Broncos','Houston Texans','Indianapolis Colts','Jacksonville Jaguars','Kansas City Chiefs','Miami Dolphins','New England Patriots','New York Jets','Oakland Raiders','Pittsburg Steelers','San Diego Chargers','Tennessee Titans');
$NFC=array(00 => ' ',01 => 'Arizona Cardinals','Atlanta Falcons','Carolina Panthers','Chicago Bears','Dallas Cowboys','Detroit Lions','Green Bay Packers','Minnesota Vikings','New Orleans Saints','New York Giants','Philadelphia Eagles','San Francisco 49ers','Seattle Seahawks','St. Louis Rams','Tampa Bay Buccaneers','Washington Redskins');
$baseline=array(01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16);
$results=mysql_query("select * from participants where League = $league and PlayerID = $player") or die('<p>lookup error. '.mysql_error());
$match_results=mysql_num_rows($results);
$row=mysql_fetch_array($results);
$nfcpicks=explode(", ",$row['NFC']);
$afcpicks=explode(", ",$row['AFC']);
echo '<br /> aprow';
print_r($row['AFC']);
echo '<br /> nprow';
print_r($row['NFC']);
echo '<br /> ap';
print_r($afcpicks);
echo '<br /> np';
print_r($nfcpicks);
//this will remove from choices the teams already picked
$nfcdifference = array_diff($baseline, $nfcpicks);
echo '<br />ndiff';
foreach ($nfcdifference as $key => $value) {
echo " $key: $value "; //display to verify
}
$afcdifference = array_diff($baseline, $afcpicks);
echo '<br />adiff';
foreach ($afcdifference as $key => $value) {
echo " $key: $value "; // display to verify
}
$afcimp=implode(", ",$afcdifference);
$afcexp=explode(", ",$afcimp);
$nfcimp=implode(", ",$nfcdifference);
$nfcexp=explode(", ",$nfcimp);
echo '<br />ai: '.print_r($afcimp);
echo '<br />ni: '.print_r($nfcimp);
echo '<br />ae: '.print_r($afcexp);
echo '<br />ne: '.print_r($nfcexp);
$afccount=count($afcdifference);
$nfccount=count($nfcdifference);
echo '<br />ac: '.print_r($afccount);
echo '<br />nc: '.print_r($nfccount);
?>
<div id="selectionform"><span id="leftsideselection">
<form method="post" action="cgi-bin/update.php" id="teamselectform">
<span id="afc"><h3>AFC Teams</h3>
<?php
for ($j=1;$j<$afccount;$j++){
$achoice=$afcexp[$j];
$nachoice=$achoice;
echo '<input type="radio" name="afc" value="'.$achoice.'">'.$AFC[$achoice].'<br />';
echo "\r\n";
}
echo"</span>\r\n";
echo'<span id="nfc"><h3>NFC Teams</h3>';
echo"\r\n";
for ($j=1;$j<$nfccount;$j++){
$bchoice=$nfcexp[$j];
$nbchoice=$bchoice;
echo '<input type="radio" name="nfc" value="'.$bchoice.'">'.$NFC[$bchoice].'<br />';
echo "\r\n";}
echo'</span>';
?>
so here's what my print and echo statements are showing me:
(these are the selections from the db)
aprow07,05,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
nprow13,04,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
(this is the selections as arrays)
apArray ( [0] => 07,05,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 )
npArray ( [0] => 13,04,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 )
(this is the result of array_diff)
ndiff 0: 1 1: 2 2: 3 3: 4 4: 5 5: 6 6: 7 7: 0 8: 0 9: 10 10: 11 11: 12 12: 13 13: 14 14: 15 15: 16
adiff 0: 1 1: 2 2: 3 3: 4 4: 5 5: 6 6: 7 7: 0 8: 0 9: 10 10: 11 11: 12 12: 13 13: 14 14: 15 15: 16 1, 2, 3, 4, 5, 6, 7, 0, 0, 10, 11, 12, 13, 14, 15, 16
Again, my questions:
1. Look at the last part of "adiff". WHY DOES the AFC data return extra info at the end? It's throwing off the results further down the line.
2. Is this the correct method for sorting out data points from an array?
Thanks.