0

I have two tables: Team and player. Team player id's table. When I run the tool url, url and name of the player Starring table, I want to take.

player table

player

p_id  p_name            p_url
1   Iker Casillas   iker-casillas
2   Mesut Ozil      mesut-ozil
3   Xavi            xavi
4   Victor Valdés   victor-valdes

team

t_id   t_name           t_url      player

1      FC Barcelona     fc-barcelona     3,4
2      Real Madrid C.F. real-madrid-cf   1,2

team url is running, players want to print the name and url.but I can not get the result. where I make mistakes.

include('confing.php');

$t_url = $_GET["t_url"];
$sql = mysql_query("select player.p_name,player.p_url from player,team where player.t_id = team.t_name and team.t_url='.$t_url.'");

while($write = mysql_fetch_assoc($sql)) {
    echo '<a href="'.$write['t_url'].'">'.$write['t_name'].'</a>';
}
John Woo
  • 258,903
  • 69
  • 498
  • 492
xsabianus
  • 1
  • 1

1 Answers1

0

you need to use FIND_IN_SET

SELECT  b.*
FROM    team a
        INNER JOIN player b
            ON FIND_IN_SET(b.p_ID, a.player) <> 0
WHERE   a.t_url = 'valueHere'

one more thing, your code is vulnerable with SQL Injection, please read the article below to prevent from it

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492