在页面中的html表中显示mySQL数据库表中的值 [英] Show values from a mySQL database table inside a html table in a page

查看:325
本文介绍了在页面中的html表中显示mySQL数据库表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据库表中检索值,并将它们显示在页面的html表中。
我已经搜索了这个,但我找不到答案,虽然这肯定是一件容易的事(这应该是数据库lol的基础)。我猜我搜索的字词有误导性。
数据库表名称是票据,它现在有6个字段(submission_id,formID,IP,名称,电子邮件和消息),但应该有另一个字段叫ticket_number。
我如何让它显示db在html表中的所有值,如下所示:

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.456.789</td>
    <td>John Johnny</td>
    <td>johnny@johnysite.com</td>
    <td>This is the message John sent you</td>
  </tr>
</table>

然后'john'下面的所有其他值。

And then all the other values below 'john'.

感谢您提前的帮助。

推荐答案

取自w3schools的示例: http://www.w3schools.com/php/php_mysql_select.asp

Example taken from w3schools: http://www.w3schools.com/php/php_mysql_select.asp

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

这是一个学习

这篇关于在页面中的html表中显示mySQL数据库表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆