Lasse Nielsen
Lasse Nielsen

Reputation: 3

Link within PHP and Database $row

I have hit a bump on my road and quite figure out how to get this working the way I want. I hope some of you can give me a helping hand with this!

Currently I have a table that displays some information from my database on my website and that is working great, however I can't figure out how I make a link within my table. I need to use an external website that I can link to and at the same time use one of my $row in the link. Here is my code:

<!DOCTYPE html>
<html>
<head>
    <title>Store Topliste</title>
</head>
<body>
<h4>Denne side viser dig en liste over dem der har flest Credits i Store</h4></br></br>
<table>
    <tr>
        <th>Rank</th>
        <th>Navn</th>
        <th>Credits</th>
        <th>Steam ID</th>
        <th>Sidst Online</th>
    </tr>
    <?php
    $conn = mysqli_connect("HOST", "DATABASE", "PASSWORD", "USER");
    if ($conn-> connect_error) {
        die("Connection failed:". $conn-> connect_error);
    }

    $sql = "SELECT name, authid, credits, date_of_last_join from store_players ORDER BY credits DESC LIMIT 250";
    $result = $conn-> query($sql);

    if ($result-> num_rows > 0) {
            $rank = 1;
        while ($row = $result-> fetch_assoc()) {
            echo "<tr><td>". $rank ."</td><td>" . $row["name"] . "</td><td>". $row["credits"] . "</td><td>" . "STEAM_1:", $row["authid"] . "</td><td>" . strftime("%d.%m.%Y %H:%M:%S", $row["date_of_last_join"]) . "</td></tr>";
            $rank++;
        }
        echo "</table>";
    }
    else {
        echo "0 result";
    }

    $conn-> close();
    ?>
</table>
<br>
<p>- Dette system er udviklet af <a href="https://steamcommunity.com/id/LasBoi">LasBoi</a> med ♥. </p>
</body>
</html>

So here is a picture of what it looks like: Website Example

What I want is that the STEAM_1:1:61281672 (" . "STEAM_1:", $row["authid"] . ") links to this address - "https://steamidfinder.com/lookup/STEAM_1:" and that the rest of the website link will be filled out by $row["authid"] so it will be a complete link to the profile on that site. And still maintain the same text structure (STEAM_1:1:61281672) that is already on my website.

Upvotes: 0

Views: 53

Answers (1)

Jay Blanchard
Jay Blanchard

Reputation: 34426

You would just create the link as part of your HTML output:

<td><a href=\"https://steamidfinder.com/lookup/STEAM_1:?steam_id=\"" . $row["authid"] . "\">STEAM_1:" . $row["authid"] . "</a></td>

Upvotes: 4

Related Questions