echo链接和字符串

时间:2016-03-20 10:54:27

标签: php

我试图在链接中回显字符串,但它不会出现在页面上。 这是我的代码:

<?php

$con = mysqli_connect("localhost","user","pass","db");

$term = mysqli_real_escape_string($con, $_GET['search']);

$sql = "SELECT * FROM `users` WHERE username LIKE '%".$term."%'"; 
$r_query = mysqli_query($con, $sql); 

while ($row = mysqli_fetch_array($r_query)){ 
echo '<a href="user.php?username=' . $row['username'] . '>$row['username']</a>';
}

?>

以前的代码只是回显了echo $row['username'];

1 个答案:

答案 0 :(得分:1)

您没有正确关闭echo string。这有效:

echo "<a href=\"user.php?username={$row['username']}\">{$row['username']}</a>";