我想从数据库表中检索值,并在页面的html表中显示它们。我已经在搜索这个,但是我找不到答案,尽管这肯定很容易(这应该是数据库的基础)。我想我搜索过的字词会误导我。数据库表名称是票据,它现在有6个字段(submission_id,formID,IP,名称,电子邮件和消息),但是应该有另一个字段称为ticket_number。我如何获取它以html表的形式显示db中所有的值:
<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>johnny@example.com</td> <td>This is the message John sent you</td> </tr> </table>
然后是“ john”下面的所有其他值。
来自W3Schools的示例:PHP从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); ?>
这是一个学习的好地方!