mysql数据传html,读从MySQL数据库中的数据到一个HTML表?

So i am working on a project and need some advice.

I have a MySQL database that stores events, i know how to code this functionality in PHP but im just stuck of a few specifics.

As the project that I am creating is a timetable, the most important attributes are the day of the event, starting time and finishing time.

Once i have read this data from the MYSQL database using my PHP script, how do i go about inserting these events in to a html timetable?

Lets say i have record like below in my events table:

Event ID = 01

Event Day = Monday

Event Start = 12:00

Event End = 14:00

How would I then put that into a html table, bearing in mind that i may have mutiple events for a day?

解决方案

You can mix your result from PHP into HTML code:

foreach ($results as result){

echo '

'.$result->field.'';

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将MySQL数据库数据显示到HTML,需要通过PHP和MySQL进行连接,并使用查询语句从数据库获取数据。然后,使用HTML和PHP代码将数据显示为格。 以下是一个简单的示例代码,可以将数据MySQL数据库取并显示为HTML格: ```php <?php //连接到MySQL数据库 $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); //检查连接是否成功 if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //查询数据库数据 $sql = "SELECT id, name, email FROM users"; $result = $conn->query($sql); //检查是否有数据 if ($result->num_rows > 0) { // 输出数据 echo "<table><tr><th>ID</th><th>Name</th><th>Email</th></tr>"; while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id"]. "</td><td>" . $row["name"]. "</td><td>" . $row["email"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } //关闭连接 $conn->close(); ?> ``` 在上述代码,我们首先连接到MySQL数据库,然后查询数据并将其存储在 `$result` 变量。接下来,我们使用 `num_rows` 方法检查是否有数据存在。如果有数据,则使用 `fetch_assoc` 方法从结果获取每一行数据并以 HTML 格的形式输出。 注意,上述代码仅为示例,实际情况下需要根据数据库的结构和要显示的数据进行相应的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值