1

有谁知道如何从 php 变量中创建链接。我希望我的 php 变量 $LeagueLink 成为带有 mysql 查询结果名称的leaguehome 链接。如果可以的话请帮忙....

$result = mysql_query("SELECT League FROM League_Info WHERE User_ID = '$id'");
$result2 = mysql_fetch_array($result);
    $result3 = $result2['League'];
    $LeagueLink = '<a href="home.com/test.php"><?=$result3?></a>';
4

2 回答 2

4
$LeagueLink = "<a href=\"http://home.com/leaguehome.php\">$result3</a>";

要将变量直接放入上面的字符串中,它需要是双引号字符串 ( "),而不是单引号字符串 ( ')

或者,如果您担心粗心引起的错误,请使用字符串连接:

$LeagueLink = '<a href="http://home.com/leaguehome.php">' . $result3 . '</a>';
于 2012-07-22T02:14:17.997 回答
1

你也可以这样做

$LeagueLink = '<a href="home.com/leaguehome.php">'.$result3.'</a>';
于 2012-07-22T02:17:09.607 回答