How to fetch real-time/live count of any php mysql

2019-07-19 03:16发布

问题:

i want show the total no of registered users in a div. But want it to show the real-time/live count.

I am ( currently ) using :

<?php 
$sql="SELECT * FROM QWERTY WHERE abc = '123' AND xyz = '789' ORDER BY id"; 
if ($result=mysqli_query($conn,$sql))  {  
   $rowcount=mysqli_num_rows($result);  
   printf("%d",$rowcount);  
   mysqli_free_result($result);  
} ?>

plz help me in displaying the real-time/live count

回答1:

You can use some jquery magic to get the current count from a remote page and then put it into your DIV.

http://paste.liam.systems/view/QZVG63LUZ9

The script above will pull from a URL every 5 seconds and add it into the div.



回答2:

this is not what i was looking for but it worked ::

1.php


<html>
    <head>

    <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
    <script>
    $(document).ready(function(){
        setInterval(function(){
            $("#count").load('2.php')
        }, 2000);
    });
    </script>
    </head>
    <body>
        <div id="count"></div>
    </body>
    </html>


2.php

<?php 
$sql="SELECT * FROM QWERTY WHERE abc = '123' AND xyz = '789' ORDER BY id"; 
if ($result=mysqli_query($conn,$sql))  {  
   $rowcount=mysqli_num_rows($result);  
   printf("%d",$rowcount);  
   mysqli_free_result($result);  
} ?>


标签: php html5 mysqli