Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show values from a MySQL database table inside a HTML table on a webpage

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'.

like image 613
Alex Avatar asked Jul 27 '13 21:07

Alex


1 Answers

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!

like image 135
Jonnny Avatar answered Sep 16 '22 17:09

Jonnny