Question

I'm a beginner so this may ba a stupid one. I'm creating simple platform, which uses a database to manage my post stamps collection. I've managed to set up a database and gather new stamps from user. Now I want to create kind of "product page", which will use data from mySQL. You will be able to enter this page through a dynamically generated table, which will contain all stamps in the database.

The code,which generates a simple table is here:

        //connect to database
    $db = mysqli_connect(database login data);
    if(mysqli_connect_errno()){
        echo "Jest problem z podłączeniem się do bazy danych. Skontaktuj się z administratorem.";
        die();
    }
    // loop through results of database query, displaying them in the table
    $result = mysqli_query($db,"SELECT * FROM stamps");
    ?>
</head>
<body>
<?php include "navbar.php" ?>
    <h1>Przeglądaj swoją kolekcję.</h1>
    <?php
    echo "<p><b>View All</b>";

    echo "<table border='1' cellpadding='10'>";
                echo "<tr> <th>ID</th> <th>Nazwa</th> <th>Kraj</th> <th>Wartość nominalna</th> <th>Wartość rynkowa</th> <th>Klaser</th> <th>More info</th> <th>Edytuj</th> <th>Usuń</th></tr>";
                while($row = mysqli_fetch_object($result)) {

                // echo out the contents of each row into a table
                echo "<tr>";
                            echo '<td>' . $row->id . '</td>';
                            echo '<td>' . $row->name . '</td>';
                            echo '<td>' . $row->country . '</td>';
                            echo '<td>' . $row->price . '</td>';
                            echo '<td>' . $row->estimated . '</td>';
                            echo '<td>' . $row->album . '</td>';
                            echo "<td><a href=\"stamp.php\">More info.</a></td>";
                            echo '<td><a href="edit.php?id=' . $row->id . '">Edit</a></td>';
                            echo '<td><a href="delete.php?id=' . $row->id . '">Delete</a></td>';
                echo "</tr>";
                }
                // close table>
    echo "</table>";
    ?>

Now, I'd like to post database values to another page, after clicking "More info" and just view it something like that:

<body>
    <?php include "navbar.php" ?>
    <div class="jumbotron">
        <img class="photo" src="http://placehold.it/250x250">
        <h1>Znaczek z XIX wieku</h1> <!-- database data goes here -->
        <h3>Informacje:</h3> <!-- database data goes here -->
        <h5>Numer katalogowy:</h5> <!-- database data goes here -->
        <h5>Rok wydania:</h5> <!-- database data goes here -->
        <h5>Kraj:</h5> <!-- database data goes here -->
        <h5>Wartość nominalna:</h5> <!-- database data goes here -->
        <h5>Wartość rynkowa:</h5> <!-- database data goes here -->
        <h5>Klaser:</h5> <!-- database data goes here -->
        <h3>Opis:</h3> <!-- database data goes here -->
        <h5><div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, aliquam, tenetur voluptatibus veritatis numquam expedita nesciunt quos repudiandae similique atque provident ipsam dolorem recusandae id possimus minus ea eum cupiditate!</div>
        <div>Sint, debitis, saepe repellendus commodi recusandae error architecto voluptates soluta ipsa facere perferendis aspernatur quo atque fugiat consequatur! Assumenda necessitatibus dolorem esse distinctio incidunt pariatur praesentium veniam voluptate quae quaerat!</div>></h5>
        <p><a class="btn btn-primary btn-lg" role="button">Edytuj</a></p>
    </div>
    <?php include "footer.php" ?>
</body>

The question is: what is the best way to do it ? Thanks in advance !

Was it helpful?

Solution

For generating page dynamically you can use $_GET['id'] for getting the id of the table, from where you are gonna fetch the data. Now put a get query after the link you wanna use,

It should look like this Index.php?id=2 It is gonna fetch all the data from the second row.

But if you are like making a admin board or anything that is gonna modify the database do not use this, use secure login with user password verification,

Be sure to sanitize the id as this is going to used for getting the data in the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top