简体   繁体   English

如何创建动态PHP页面

[英]How to create a dynamic php page

So it's actually hard to explain what I mean. 因此,实际上很难解释我的意思。

So I have this list here. 所以我在这里有这个清单。 Its pulls data from the db and then displays it in a DIV on my webpage. 它从数据库中提取数据,然后将其显示在我的网页上的DIV中。

I want it to only show the first 4 listing. 我希望它只显示前4个清单。 Then after 4 seconds. 然后4秒钟后。 I want it to show the next 4 listening and keep revolving like that infinitely. 我希望它显示接下来的4个聆听,并像这样无限旋转。 If someone could point me in the direction to be able to do that. 如果有人可以指出我的方向去做到这一点。 Also, It needs to be updating dynamically every 4 seconds. 另外,它需要每4秒动态更新一次。 Not when the user hits refresh. 当用户点击刷新时不会。

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

What you can do is javascript, and use ajax. 您可以做的是javascript,并使用ajax。 to load it every four seconds you can use setInterval( http://www.w3schools.com/jsref/met_win_setinterval.asp ), but for me its better if you use jQuery load more data on scroll . 每四秒钟加载一次,您可以使用setInterval( http://www.w3schools.com/jsref/met_win_setinterval.asp ),但对我来说,如果您使用jQuery在滚动上加载更多数据会更好。

to limit output use the limit of mysql. 要限制输出,请使用mysql的限制。

see this article: http://www.mysqltutorial.org/mysql-limit.aspx 看到这篇文章: http : //www.mysqltutorial.org/mysql-limit.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM