esiason14 Posted October 24, 2005 Share Posted October 24, 2005 I have a simple search, where users can query on a players last name, but I want to add something to the search results. Right now it displays, the player with a link to his profile, but I want to add the team name after...Like this: Player Name, Team Name Heres the meat of my results page: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]if ($lname == \"\") {$lname = \'%\';} $result = mysql_query (\"SELECT fname, lname, player_id FROM players WHERE lname LIKE \'%$lname%\' \",$conn); echo \"<table align=\\"center\\" width=\\"55%\\" border=\\"1\\" cellpadding=\\"2\\" cellspacing=\\"0\\">\"; echo \"<TR align=\\"center\\"><td><b>Players found: </b> </td></tr>\"; if ($row = mysql_fetch_array($result)) { $fname = $row[\'fname\']; $player_id = $row[\'player_id\']; $nflteamname = $row[\'nflteam_name\']; do { print \"<TR><TD> <a href=\'/football/players.php?player_id=\" . $player_id . \"\'> \".$fname.\" \".$lname.\"</a>\".$nflteamname.\"</TD></TR>\"; } while($row = mysql_fetch_array($result)); } else {print \"Sorry, no records were found!\";} print \"</table>\"; ?>[/span][!--PHP-Foot--][/div][!--PHP-EFoot--] This is the query for the NFL team name, but I'm just having trouble working it in... SELECT players.nflteams_id, nflteam_name, player_id FROM players, nflteams WHERE nflteams.nflteam_id = players.nflteam_id If you want to try it out....search for the name "Kennison" here http://www.fantasyfootballresearch....ball/search.php Another problem I'm having is if you query for a common name such as smith. It returns only the first occurence of Smith, but multiple times. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 30, 2005 Share Posted October 30, 2005 Make your initial query : [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] p.fname, p.lname, p.player_id, t.nflteam_name FROM players p INNER JOIN nflteams t ON p.nflteam_id = t.nflteam_id WHERE lname LIKE '%$lname%' [!--sql2--][/div][!--sql3--] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.