I'm progressing on a player database for a side interest and need some help. I'm not sure what exactly I'm not doing right here. I have an HTML form that passes a string to the php page for processing. My search works fine, I can enter a first or last name in the form and bring up the player list of those matching said data in a table. The problem is that I'm entering about 9 seasons (to date, more to come) of data so there will be one entry for each player for each season. On the results page I only want to have one result per player show up as I have a working link to a stat page for that player. I've fooled around with the array_search() but haven't had any luck yet. Here's my code:
$resultID = mysql_query("SELECT * FROM hitting WHERE lastname='$data' OR firstname='$data'") or die(mysql_error());
print "<table border=\"1\">";
print "<tr><th>Player</th></tr>";
$temp=array();
for ($x=0; $x<mysql_num_rows($resultID); $x++)
{
$row = mysql_fetch_assoc($resultID);
$firstname=$row[firstname];
$lastname=$row[lastname];
if(array_search($firstname,$temp)!==TRUE && array_search($lastname,$temp)!==TRUE)
{
print "<tr>";
print "<td><center><a href=\"player.php?firstname=$firstname&lastname=$lastname\">" . $row[firstname] . " " . $row[lastname] . "</a></center></td>";
print "</tr>";
}
else {
exit();
}
//After I've found the name once, I store it in the temp array so that it will HOPEFULLY be caught when the for loop starts again and it will exit out of the loop before it prints the duplicate results again.
array_unshift($temp, "$firstname");
array_unshift($temp, "$lastname");
}
print "</table>";
It's the if statement that is the work in progress. Taking out the if statement and array_unshift() statements and leaving the 3 print statements work fine, but as I said, I get duplicate results if the player is in the DB twice.