如何创建一个动态的 php 页面


How to create a dynamic php page

>所以实际上很难解释我的意思。

所以我这里有这个列表。它从数据库中提取数据,然后将其显示在我网页上的 DIV 中。

我希望它只显示前 4 个列表。然后在 4 秒后。我希望它显示接下来的 4 个聆听并无限地继续旋转。如果有人能为我指明方向,就能做到这一点。此外,它需要每 4 秒动态更新一次。当用户点击刷新时不会。

<?php session_start(); ?>
            <head>
            <link rel="stylesheet" type="text/css" href="tablecss.css">
            <style type="text/css">
                .extra {
                    position: relative;
                    top: 50px;
                }
                body {
                    overflow: hidden;
                }

            </style>
            </head>
            <body>

            <?php
            $con = mysqli_connect('##', '##', '##', '##');
            if(mysqli_connect_errno()) {
              echo 'Failed to Connect to MySQL' . mysqli_connect_errno();
            } 
            $user = $_SESSION['username'];
            $result = mysqli_query($con, "SELECT * FROM corporations");
            echo "<table id='tb'border='1'>
            <tr>
            <th>Name</th>
            <th>Owner</th>
            <th>Last Price</th>
            <th>Volume</th>
            </tr>";

            while($row = mysqli_fetch_array($result)) {
            echo "<tr>";



                echo "<td>" . $row['name'].    "</td>";
                echo "<br>";
                echo "<td>" . $row['owner'] . "</td>";
                echo "<br>";
                echo "<td>" .'$'. $row['shareValue'] . "</td>";
                echo "<br>";
                echo "<td>" . $row['publicShares'] . "</td>";
                echo "<br>";    
            } 
            mysqli_close($con);
            ?>
            </div>
            </body>

你可以做的是javascript,并使用ajax。 每四秒加载一次,你可以使用 setInterval(http://www.w3schools.com/jsref/met_win_setinterval.asp),但对我来说,如果你使用 jQuery 在滚动时加载更多数据会更好。

要限制输出,请使用 MySQL 的限制。

请参阅本文: http://www.mysqltutorial.org/mysql-limit.aspx