Search code examples
phpechohref

Echo a href in mysql data fetch query results in PHP


I have a SELECT query to fetch user id, name and email from user table.

I want to place a link to loadwu.php page with fetched user id argument in the fetched result table. The echo statement looks like this

echo "<tr><td>{$row['id']}</td><td>{$row['uname']}</td><td>{$row['uemail']}</td><td>{<a href="loadwu.php?id=$row['id']">Select</a>}</td></tr>";

The problem part in this echo statement is

<td>{<a href="loadwu.php?id=$row['id']">Select</a>}</td>

What is the correct formatting for this part?


Solution

  • You need to escape the double quotes which is used with href attribute.

    echo "<tr><td>{$row['id']}</td><td>{$row['uname']}</td><td>{$row['uemail']}</td><td>{<a href=\"loadwu.php?id={$row['id']}\">Select</a>}</td></tr>";