-1

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.

I want it to only show the first 4 listing. Then after 4 seconds. I want it to show the next 4 listening and keep revolving like that infinitely. If someone could point me in the direction to be able to do that. Also, It needs to be updating dynamically every 4 seconds. 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>
Kevin1990
  • 31
  • 4
  • 2
    To add truly dynamic content to a web page without user intervention, you need to study Ajax. You will load the page with content in the div. After 4 seconds, you use Ajax to get new content for the div. 4 seconds later, you repeat. There is a problem here... It can easily take more than 4 seconds to pull new content. So, I suggest making it wait 4 seconds, pull content (however long that takes), and then wait 4 seconds again. – kainaw Mar 12 '15 at 13:41
  • Could I do a range in a WHERE of the MySQL queries? for example "SELECT * FROM corp WHERE id = 1-4" – Kevin1990 Mar 12 '15 at 13:42
  • Ok, Ajax. Going to study on it now. Thanks a lot. I appreciate it. – Kevin1990 Mar 12 '15 at 13:43
  • That would be useful for getting the content. You have two sides to this problem. I explained the browser side above (using ajax). On the server side, you query your database. You can use offset and limit to get a specific set of responses from the database. – kainaw Mar 12 '15 at 13:43
  • If you want to use a range and checking for id's from 1 to 4, you'd need to use `IN()` or `FIND_IN_SET()` or possibly `BETWEEN()`. Pagination could also be another option in conjunction with Ajax/JS. – Funk Forty Niner Mar 12 '15 at 13:44
  • @Fred-ii- Thanks, I appreciate the response. – Kevin1990 Mar 12 '15 at 13:46
  • You're welcome Kevin. – Funk Forty Niner Mar 12 '15 at 13:46

1 Answers1

2

What you can do is javascript, and use 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.

to limit output use the limit of mysql.

see this article: http://www.mysqltutorial.org/mysql-limit.aspx

Community
  • 1
  • 1
DarkZ3ro11
  • 128
  • 7