Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I want to show values retrieved from a database table in a HTML table page. I did a lot of research but I could not find any answer to it. The database table name is tickets, it contains 6 fields right now (submission_id, formID, IP, name, email, and message) but should have another field called ticket_number. Please help me out with 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>

1 Answer

0 votes
by (11.7k points)

Please follow the code given down below:

<?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);

?>

If you want to get more insights into SQL, checkout this SQL Course from Intellipaat.

Related questions

Browse Categories

...