在PHP中的HTML表中显示查询结果 [英] Displaying query result in a HTML table in PHP

查看:279
本文介绍了在PHP中的HTML表中显示查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在网页中显示表格。表中的数据来自数据库,我可以使用mysql php库查询。我正在寻找一个模板/示例如何提出一个漂亮的表(我不擅长前端设计)。

I need to display a table in a web page. The data from the table comes from database which I can query using mysql php library. I am looking for a template/example of how to come up with a nice looking table (I am not good at front end design).

任何链接/示例/参考

推荐答案

这是一个如何将MySQL表读入HTML表的示例。

Here is an example on how to read a MySQL table into a HTML table. And no, it does not look nice.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Read values from MySQL</title>
    </head>
    <body>
        <?
            mysql_connect($db_host,$db_user,$db_pw);
            mysql_select_db($db_name);
        ?>
        <table border="1">
            <tbody>
                <?
                    $result = mysql_query("SELECT firstname, lastname FROM persons")
                        OR die(mysql_error());
                    while($row = mysql_fetch_assoc($result)) {
                        echo '<tr><td>' . $row['firstname'] . '</td><td>' . $row['lastname'] . '</td></tr>';
                    }
                ?>
            </tbody>
        </table>
    </body>
</html>

这篇关于在PHP中的HTML表中显示查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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