Jump to content


Photo

search help


  • Please log in to reply
1 reply to this topic

#1 esiason14

esiason14
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 24 October 2005 - 05:54 PM

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.fantasyfo...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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 October 2005 - 07:14 PM

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--]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users