2015-09-04 25 views
3

今天我在我的网站上工作,试图展示最后一场比赛的胜利者。这里是我的代码:Mysql_query如何将它与“动态”数据库一起使用?

$lastgame = fetchinfo("value","info","name","current_game"); 

$winnercost = fetchinfo("cost","games","id",$lastgame-1); 
$winnerpercent = round(fetchinfo("percent","games","id",$lastgame-1),1); 
$winneravatar = fetchinfo("avatar","users","steamid",$lastwinner); 
$winnername = fetchinfo("name","users","steamid",$lastwinner); 



echo '<p>Game #'.$lastgame.'</p>'; 
echo '<p>'.$winnername.' won the jackpot</p>'; 
echo '<p> valued at '.$winnercost.'</p>'; 
echo '<p>with a winning chance of '.$winnerpercent.'</p>'; 

的一点是我使用fetchinfo而已,所以它显示的信息,但在实际的时候,我必须刷新我的网页显示的最新赢家。我需要做一个mysql_query我猜。

我的问题是,我不明白如何使用mysql_query,知道每次获胜者赢得它会在我的表中创建一个新行。例如:

id : 1 
startime :1441330544 
total price : 3.17 
Winner : Foxy 
steam id : 76561198042016725 
Percent chances to win : 98.7381703 
Number of total item : 2 
module : 0.24973750 

任何人都有解决方案来帮助我吗?这个-1

,$lastgame-1),1); 

给我一些困难:(

网站上的ATM结果:

游戏#4 狡猾韩元面值3.31 具有94.6获胜的机会中大奖

+0

从这里使用[PHPLink](http://php.net/manual/en/mysqli.query.php) –

+0

由于没有人提到过它,让我指出PHP的mysql_query()函数已被弃用(以及整个'mysql' API),并且将在下一版本的PHP中被完全删除。你应该改用你的代码来代替使用'mysqli'或'PDO'库。另外,如果你是一个PHP初学者,并且你使用了'mysql_xxx()'函数,那么这可能意味着你已经使用了一些非常古老的教程来自学PHP;我强烈建议您尝试查找一些更新的教程,因为PHP已经成为一种语言,因为'mysql' funcs已被弃用 – Simba

回答

2

根据您所提供的信息,我想你可以用最简单的查询会是这样的:

select * from <tblname> order by steamid desc limit 1; 

自动刷新,你可以做两两件事之一:

1) you could add: <meta http-equiv="refresh" content="5"> in the header of your html and the page will automatically refresh every 5 seconds. (basic) 

2) you could use ajax to make a call to execute the query and update the page which is a much nicer user experience (more advanced) 
0

进行API页面用PHP或任何其他优选的服务器端编程的网络语言,它调用的时候给你最最新查询结果它可以。

然后在JavaScript中创建一个循环,每隔x秒钟向api页面发送一个ajax请求并使用该数据,您可以使用jquery或js动态更新您的字段(实际上并不重要 - 您可能知道如何更新/改变文字)

这里的一些资源:

AJAX入门 link 1

更AJAX link 2

相关问题