Help displaying url links from Mysql database on webpage


#1

Hi
I have a DB that contains URL’s - I need to display these URL’s on the webpage so readers can click on them and link to the relevant page but after many days of trying I am at a loss as to how to code the a href tag within the php code.
below is a snippet of the code i am using and I need to wrap the a href tag around the ".$row[“link”].
I appreciate any help with this
Thanks in advance

[php]$sql = “SELECT link, address, description, price FROM reales WHERE suburb=‘Morley’”;
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo “

”;
// output data of each row
while($row = $result->fetch_assoc()) {
echo "




";
            }
echo "</table>";[/php]
“.$row[“link”].” “.$row[“address”].” “.$row[“description”].” “.$row[“price”].”

#2

I strongly suggest you stop echoing HTML from PHP. It only makes your life miserable

Notice below how the syntax slightly changes from the top to the bottom. Your editor will also catch up on syntax highlighting the HTML when it’s not just a string that’s being echoed. I find it much easier to work with the output when echoing PHP inside HTML instead of echoing everything from PHP.

[php]<?php

$sql = “SELECT link, address, description, price FROM reales WHERE suburb=‘Morley’”;
$result = $conn->query($sql);

?>

<?php if ($result->num_rows > 0): ?>
<table class='relist'>
    <tr>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
    </tr>
<?php while($row = $result->fetch_assoc()): ?>
    <tr>
        <td class='rel'><?= $row["link"] ?></td>
        <td class='rel'><?= $row["address"] ?></td>
        <td class='rel'><?= $row["description"] ?></td>
        <td class='relp'><?= $row["price"] ?></td>
    </tr>
<?php endwhile; ?>
</table>
<?php endif; ?>[/php]

Note that I haven’t actually added the link tag. I suspect it will be much easier now though.


#3

Thank you Jim