PHP refresh SQL Data without refreshing the page

Asked

Viewed 92 times

0

I have a website where shows data from Database to Page.

If these data are changed in the database, automatically it will show them on the page, without refreshing the page, just refresh the code in real time.

I use id='refresh' for such an equation, but.. since I don’t know how to do it...

How do I do that?

                 $steamID = $_SESSION['steamid'];

                $db = mysqli_connect($host, $username, $password, $dbname );
                // Check connection

                if (mysqli_connect_errno())
                {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                $getC = mysqli_query($db,"SELECT credits, level, exp FROM users_steam WHERE steamid ='$steamID' ");

                while($row = mysqli_fetch_array($getC))
                {   
                    $exp = $row['exp'];
                    $lvl = $row['level'];

                   /* if($lvl == 100 && ($exp == 0)) {

                        $confirm = '';

                    } else {
                        $confirm = ' <span class="levels"> Exp </span>'. $exp;
                    }*/

                    echo "<li><a href='buy.php' alt='Silver Coins' id='refresh'><span class='currency-w'>" . number_format($row['credits'],0) . "</a></span></li>";
                    echo "<li><a href='profile.php'><span id='levels' class='levels'>level </span>" . $row['level'] . "</a></li>";
                    echo "<li></li>";

                }

2 answers

0

Quick response.:

Não é possível apenas com PHP

More elaborate answer.:

PHP é do lado do servidor e não do lado do cliente.
O que poderá fazer é utilizar uma linguagem do lado do cliente e fazer requisições ao servidor e atualizar apenas o conteúdo que pretende exemplo usar ajax do jquery.

0

You can do this using jQuery.

$.ajax({
  type: 'POST',
  url: 'CAMINHO DO SEU ARQUIVO PHP',
  success: function(data){
     // Retorno com data
  }

})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.