如何从数据库中获取可点击链接列表

I have a database were the information from the database comes on to my website (code below).

On another page I have a text box were you type in a new table, it creates a new table and sends the table name to another table which stores all the tables. I want to view all the tables from that table list but have them when i click on them take me to view the other tables.

I have very little experience with databases and PHP but I'm thinking if I can store the table variable in cookies and then initiate it in another document and have it resets every time the user returns to the page which has all of the other tables they can view.

But I still don't know how to create links to that other doc which runs all the other tables.

This text below is in a file called db_results.php

<?php
    $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "myDB";


    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
    } 

    $sql = "SELECT id, firstname, lastname FROM MyGuests ORDER BY id DESC LIMIT 500";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

         while($row = $result->fetch_assoc()) {
             echo "<p>". $row["firstname"]. " " . $row["lastname"] . "</p>";
         }
    } else {
         echo "0 results";
    }

    $conn->close();
?>

this code views the results and is just called index.php

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        $(document).ready(function(){
            setInterval(function() {
                $("#load_results").load("db_results.php");
            }, 1000);
        });

    </script>

    <div id = "load_results"></div>

the code is not setup for links yet but the links would go into last name and the viable name into first. please message me for any further questions.

You will have to change the echo to echo a link.

If it really goes into your last name field it would look something like this:

echo "<p>". $row["firstname"]. " <a href="url">" . $row["lastname"] . "</a></p>";

But it wouldbe better if you created another field in your table to insert the link into.