gpt4 book ai didi

php - MYSQL实时显示

转载 作者:行者123 更新时间:2023-11-29 18:46:03 24 4
gpt4 key购买 nike

我希望我的网站显示每个用户的硬币,当我向用户添加一些硬币时,我希望他不需要重新加载页面即可获得正确的金额。

这么短,我只想实时显示 mysql 值。

我的代码

                <?php
if($admin == 1)
{
echo'
<li class="text-muted menu-title">Admin Panel</li>
<li class="has_sub admin-content">
<a href="#" class="waves-effect '; if($page=="ad"){echo'subdrop';} echo'"><i class="ti-user"></i><span>Admin</span> </a>
<ul class="list-unstyled '; if($page=="ad"){echo'"style="display: block;"';} echo'" style="">
<li><a href="apu.php">Premium users</a></li>
<li><a href="abu.php">Banned users</a></li>
<li><a href="au.php">Users</a></li>
</ul>
</li>
';

}
if(isset($_GET["action"]))
{
if($_GET["action"] == "view")
{
$sid = $_GET["id"];
}
if($_GET["action"] != "view")
{
echo '<script>location.href="index.php" </script>';
}

}
if(!isset($_GET["action"]))
{
if(isset($_SESSION["steamid"]))
{
$sid= $_SESSION['steamid'];
}
else
{
echo '<script>location.href="index.php" </script>';
}
}

$sid=mysql_real_escape_string($sid);

$exists=fetchinfo("steamid","users","steamid",$sid);

if(!$exists)
{
echo '<script>location.href="index.php" </script>';
}

$crdts=fetchinfo("credits","users","steamid",$sid);


if($reg)
{
$reg2date=date('Y-m-d', $reg);
}
else
{
$reg2date='Unknown';
}
if($gp==0 || $gw==0)
{
$wr=0;
}
else
{
$wr=($gw/$gp)*100;
}

if($premium==1)
{
$id=$_SESSION['steamid'];
$time=time();
$puntil = fetchinfo("puntil","users","steamid","$id");
if($puntil<=$time)
{

mysql_query("UPDATE users SET `premium`='0' WHERE `steamid`='$id'");
mysql_query("UPDATE users SET `profile`='1' WHERE `steamid`='$id'");

}
}

?>


<div class="credits1">
<li class="text-muted menu-title">Credits</li>
<br>
</div>
<div id="credits"><?php echo $crdts; ?></div>
感谢您的关注,希望您能帮助我。

最佳答案

您需要使用ajax请求从源获取异步数据。最常见的方式是javascript ajax请求,但我假设你已经了解jquery,如果不知道你可以快速了解它,请参阅:http://jquery.com

首先您需要设置一个 php 文件,该文件从您需要的数据库返回数据

假设ajax.php

// make db connection
// get related data from db
// return the data (coins)

// set result array
$result = [
'coins' => $dbResult['coins']
];

// you can use json, so that you can easily manipulate it
// encode to json the array
$json = json_encode($result);

echo $json;

// or you could jus echo the coins as well, like:
echo $dbResult['coins'];

ajax.js

$(function(){
$.ajax({
url: "/api/getWeather",
dataType: json, // if you get a json, using this better than parsing result to json
success: function( result ) {
// updating coins in the DOM for json return
$( "selector to show coins" ).text(result.coins);

// or updating coins for plain text return
$( "selector to show coins" ).text(result);
}
});
});

您也可以更新代码或向代码添加新功能。

关于php - MYSQL实时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44641234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com