0

I have a small problem, or I just can't find the solution. I have follow code in my site place.php

<?php $con = mysqli_connect("localhost", "root", "", "vmaxdbweb"); $res = mysqli_query($con, "SELECT * FROM tblplatz");

// Tabellenbeginn
echo "<table class='tbl'>";

    // Überschrift
    echo "<th>ID</th> <th>Bezeichung</th> <th>Code</th>";
    echo "<th>Notizen & Beurteilung</th> <th>Geodaten</th> <th>Details</th>";

    $lf = 1;
    while ($dsatz = mysqli_fetch_assoc($res))
    {
        // Speichere die Daten in der Sitzung mit dem Schlüssel 'pla_id'
        echo "<tr>";
        echo "<td>" . $dsatz["pla_id"] . "</td>";
        echo "<td>" . $dsatz["pla_bezeichnung"] . "</td>";
        echo "<td>" . $dsatz["pla_code"] . "</td>";
        echo "<td>" . $dsatz["pla_notiz_beurteilung"] . "</td>";
        echo "<td>" . $dsatz["pla_geodaten"] . "</td>";
        echo "<td><a href='content\placedetail.php?id=".$dsatz["pla_id"]."'>Details</a></td>";
        $lf = $lf + 1;
    }
    // Tabellenende
echo "</tabelle>";

mysqli_close($con);
?>

my laylout on the website looks like this

<!DOCTYPE html>
<html lang="en">
    <?php include __DIR__.'/header.inc.php' ?>

    <body>       
    <div class ="banner">   
        <h4>VmaxDB Web</h4>
        </div>
        <div class = "main">

            <div class = "menu">
                <header class="container">
                <?php include __DIR__.'/nav.inc.php' ?>
                </header>
            </div>          

            <div class = "stage">
                <div class = "stage-header">
                    <?=$title?>
                </div>
                                                  
                <div class = "content">
                    <main class="container">
                        <?php include __DIR__.'/../content/'.$currentPage.'.php' ?>
                    </main>
                </div>
            </div> 

        </div>   

        <div>
            <?php include __DIR__.'/footer.inc.php' ?>
        </div>

    </body>

</html>

and i would like open the link

echo "<td><a href='content\placedetail.php?id=".$dsatz["pla_id"]."'>Details</a></td>";

from site place.php

in the content/container place

Does anyone happen to have an idea? :) I've tried many things, unfortunately I can't find the solution, it always opens a new tab.

IMSoP
  • 89,526
  • 13
  • 117
  • 169

1 Answers1

0

Links in HTML are just a way to tell the browser to go to a new URL. They don't load content into a particular part of the page, or interact with the current page in any way.

So the simple answer is to make your link point to a complete page, which repeats the parts you want to be the same - such as your existing includes for header and footer. The PHP code can decide dynamically what to show based on query string parameters available in the $_GET array.

That said, there are two main ways you can load content into part of the page:

  • Using an <iframe> tag, which you could very roughly think of as embedding an extra browser tab inside the content. See for instance the MDN guide to the iframe element.
  • Using JavaScript running in the browser to fetch the new page from the server on the background, then insert it into the current page. For largely historical reasons this is called "AJAX", and you will find thousands of pages describing related techniques, and hundreds of libraries and frameworks built on top of those ideas. The modern building block for this is the fetch API.

Both techniques are a lot more fiddly to get right than just loading a full new page - particularly to avoid annoying users by breaking features like bookmarks and back/forward buttons.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • Sorry guys, I am the absolute beginner. :( – Frontwichtel Jul 23 '23 at 13:06
  • @Frontwichtel No need to apologise, we all have to start somewhere! – IMSoP Jul 23 '23 at 13:20
  • Thank you IMSop! You have a example for me about the get vision in this case? – Frontwichtel Jul 23 '23 at 15:17
  • The version with the reload page sounds easier to me, how could I implement this idea? – Frontwichtel Jul 23 '23 at 17:55
  • @Frontwichtel I'm not sure what code would be useful. You already have some code that lays out a header and footer with some content in between, and some code for getting data from the database. All you need is a different piece of code that runs some SQL using the ID you're passing on the query string - just make sure you [use correctly parameterised queries to avoid attackers manipulating your database](https://stackoverflow.com/q/60174/157957). – IMSoP Jul 23 '23 at 18:27