I have a form that has a dropdown list and a search field. My problem is when I choose the dropdown search it doesn't return the search for the field I chose. If I search by last name it works fine. The dropdown has a list of football positions (i.e. all qb, all rb, all wr, etc...) this won't pull just the players for the selected position unless I free the results of the name search before it even starts...then it doesn't work.
I've been told to use an exit but that killed the script.
CAN SOMEONE HELP PLEASE???????
<?
$pos = $_POST["pos"];
$lastname=$_POST["lastname"];
if ($lastname == " ")
{$lastname = '%';}
if(empty($lastname))
echo "There is no value in lastname";
else
echo "<p><em>Search Results for:</em> <strong>$lastname</strong>:</p>";
/* SQL QUERY */
$all = "SELECT Player, Pos, Team FROM players_
WHERE Pos='$pos'";
$result1 = mysql_query($all);
$find = "SELECT Player, Pos, Team FROM players_
WHERE Player LIKE '$lastname%'";
$result2 = mysql_query($find);
/* PRINT RESULTS */
print "<table>\n";
print "<td><strong>Player</td><td><strong>Pos</td><td><strong>Team</td>";
while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print stripslashes("\t\t\<td>$col_value</td>\n");
}
print "\t</tr>\n";
}
mysql_free_result($result1);
while ($line = mysql_fetch_array($result2, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print stripslashes("\t\t\<td>$col_value</td>\n");
}
print "\t</tr>\n";
}
print "</table>\n";
/* Results */
mysql_free_result($result2);
?>