Sam
Sam

Reputation: 1381

put a hyperlink on table data when using with echo

I am using the following code to display data in the form a table

echo "<table id='admin'>
<tr>
<th>ID</th>
<th> Name </th>
th>Email</th>
<th>Headline</th>
</tr>";
while($row = mysqli_fetch_array($result)) 
{
echo "<tr>" ;
echo "<td>" . $row['id'] ."</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['headline'] . "</td>";
echo "</tr>";
}

I have found many similar question but they mostly displayed hyperlink along with simple echo and their solution didn't work for me. I want that what ever data gets printed in this line i.e echo "<td>" . $row['name'] . "</td>"; should also behave as a hyperlink and redirect to another page. i tried to insert href link after but it showed syntax error. Any help would be appreciated `

Upvotes: 0

Views: 2772

Answers (3)

coDe murDerer
coDe murDerer

Reputation: 1876

echo "<td><a href='other.php'>" . $row['name'] . "</a></td>";

And also,

th>Email</th>

replace this with

<th>Email</th>

Upvotes: 0

Yatin Mistry
Yatin Mistry

Reputation: 1264

Like This

echo "<table id='admin'>
<tr>
<th>ID</th>
<th> Name </th>
th>Email</th>
<th>Headline</th>
</tr>";
while($row = mysqli_fetch_array($result)) 
{
echo "<tr>" ;
echo "<td><a href='#'>" . $row['id'] ."</a></td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['headline'] . "</td>";
echo "</tr>";
}

Upvotes: 2

Sougata Bose
Sougata Bose

Reputation: 31739

echo "<td><a href='link'>" . $row['name'] . "</a></td>";

Upvotes: 1

Related Questions