I'm retrieving some data from my database and using PHP to display it. That part it working fine. I then want the data presented to be a link as well. I've been trying to wrap my output inside an <a>
tag, but so far without succes.
I can't figure out why there is no link to be found on my data when I wrapped it inside an <a>
tag:
<?php
while ($row = mysqli_fetch_array($query)) {
echo
"<tr>
"?> <a href="http://example.com"> <?php echo "<td>
{$row['Exam']} //This is my output
</td>"?></a>
</tr>
";
} ?>
Your code cannot decide if it is HTML or PHP. Why not use PHP for all:
echo '<tr><td><a href="http://example.com">'.$row['Exam'].'</a></td></tr>'.PHP_EOL;
I also put the <a>
inside the <td>
table cell tag, and you might have a quoting problem.
Alternatively, if you start with HTML you could do this:
<tr><td>
<a href="http://example.com"><?php echo $row['Exam']; ?></a>
</td></tr>
Simplified version with correct tags' sequence (you cannot wrap td
in a
).
while ($row = mysqli_fetch_array($query)) {?>
<tr>
<td>
<a href="http://example.com">
<?=$row['Exam']?>
</a>
</td>
</tr>
<?php
}
The link should be inside the <td>
<td><a href="http://example.com">Link Name </a></td>