Reputation: 55
I am trying to create an output table in PHP after extracting data from a database. The fourth column needs to be a hyperlink. I have used the following code. But I am getting error in regards to the hyperlink section. Could you please let me know how to rectify it?
Thanks!
echo"<tr>
<td>".$row["name"]."</td>
<td>".$row["age"]."</td>
<td>".$row["sex"]."</td>
<td><a href= "https://weblink.com/path1/path2/test.php?name='.urlencode($row["name"]).'&age='.urlencode($row["age"]).'">Click for next</a></td>
</tr>";
Upvotes: 2
Views: 54
Reputation: 2800
Looking at your forth <td>
your code is attempting to end the echo after href="
, hence you have to escape the quotation mark href=\"
. If this looks too ugly you can also use single quotes instead.
echo"<tr>
<td>".$row["name"]."</td>
<td>".$row["age"]."</td>
<td>".$row["sex"]."</td>
<td><a href=\"https://weblink.com/path1/path2/test.php?name=".urlencode($row["name"])."&age=".urlencode($row["age"])."\">Click for next</a></td>
</tr>";
Upvotes: 1
Reputation: 1770
I started php not long ago and I realized that it can be useful to format your code differently for clarity. Try using your tags differently if you can, for exemple:
// end php and switch to html
?>
<tr>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["age"]; ?></td>
<td><?php echo $row["sex"]; ?></td>
<td><a href= "https://weblink.com/path1/path2/test.php?name=<?php echo urlencode($row["name"]); ?>&age=<?php echo urlencode($row["age"]); ?>">Click for next</a></td>
</tr>
<?php // resume php
Upvotes: 0