I want to retrieve the values from a database table and show them in a html table in a page. I already searched for this but I couldn't find the answer, although this surely is something easy (this should be the basics of databases lol). I guess the terms I've searched are misleading. The database table name is tickets, it has 6 fields right now (submission_id, formID, IP, name, email and message) but should have another field called ticket_number. How can I get it to show all the values from the db in a html table like this:
<table border="1"> <tr> <th>Submission ID</th> <th>Form ID</th> <th>IP</th> <th>Name</th> <th>E-mail</th> <th>Message</th> </tr> <tr> <td>123456789</td> <td>12345</td> <td>123.555.789</td> <td>John Johnny</td> <td>[email protected]</td> <td>This is the message John sent you</td> </tr> </table>
And then all the other values below 'john'.
Example taken from W3Schools: PHP Select Data from MySQL
<?php $con=mysqli_connect("example.com","peter","abc123","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM Persons"); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>
It's a good place to learn from!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With