Reputation: 48
Today i'm working on my website, trying to display the last winner of the game. Here's my code :
$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>';
The point is i use fetchinfo only, so it displays informations but not in real time, i have to refresh my page to display the latest winner. I'll need to make a mysql_query i guess.
My problem is that i don't understand how to use the mysql_query, knowing that each time a winner wins it creates a new row in my table. For example :
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
Anyone has a solution to help me ? this -1
,$lastgame-1),1);
gives me some difficulties :(
The result on the website atm :
Game #4 Foxy won the jackpot valued at 3.31 with a winning chance of 94.6
Upvotes: 3
Views: 98
Reputation: 452
Make an api page with a php or any other preferred serverside programming web language that when called gives you the most up to date query results it can.
Then create a loop in javascript that every x amount of seconds sends an ajax request to the api page and using that data,you can dynamically update your fields with jquery or js (really doesnt matter - you probably know how to update/change text)
Here some resources:
ajax getting started link 1
more ajax link 2
Upvotes: 0
Reputation: 163
Based on the information you provided, I think the simplest query you could use would be something like:
select * from <tblname> order by steamid desc limit 1;
For the auto refresh you could do one of two things:
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)
Upvotes: 2