- Home /
Unify "serverside highscores" - reading in a webpage
Hello all.
I got the unify script for serverside high scores working on my android game, and it will post and get scores from the editor or from the devices without problems.
See here: http://www.unifycommunity.com/wiki/index.php?title=Server_Side_Highscores
The thing I need to do/learn is, how can I setup my webpage to have a table showing these high scores from the MySQL database?
You know something like:
top scores:
1. billy 55,000
2. johnny 45,000
3. frank 30,000
4. wallace 1,000
all of that, inside my webpage, so I guess what I need is some HTML/PHP help, in getting the information out of the MySQL database, and making it a readable form in a web browser somehow.
Now I looked into creating a web page with data from MySQL pages, but everything gets so complicated for most peoples databases! Being that my database only holds a name and a score pretty much, the complex tuts I find online dont really apply to me, and are just too far outside of my PHP knowledge in general (why didnt they just make the internet all C# haha). I need something really more geared for us unity people, and that specific serverside high scores MySQL setup...
UPDATE: Okay, I have the answer for those looking to get your high scores onto your webpage(assuming you set them up exactly like the unify community instructs you)...see answer below
@$$anonymous$$DReptile You can go to a webpage that does this and rt click-view source. That shows the source code(as im sure you know) and you can see how they do it. Im a noob when it comes to that stuff, but looking at others code may help you better understand how they did it.
@hijinxbassist Hello again hijinxbassit! You know, actually thats not a half bad idea, I think i will go into my ad$$anonymous$$ view, and see the HT$$anonymous$$L they use to display it, then just use the same query to the database to arrange the info on my site...ill try this now, but if anybody knows a less...reverse engineered way...lol let me know
Answer by MD_Reptile · Jun 03, 2012 at 04:57 AM
What you will need to do is this:
Open a blank notepad or similar.
On this notepad, copy the PHP script below.
Change the spots where is says "YourWhatever" to match your database.
For your webpage, in the spot where you want your scores to display, paste this whole thing in, and it will display all the scores in a list, numbered 1 to whatever your lowest score is.
Here is the PHP I used exactly (anywhere saying YourSomething - insert your information for your database there)
<?php
// Send variables for the MySQL database class.
$database = mysql_connect('YourDataBaseURL', 'YourUserName', 'YourPasswordHere') or
die('Could not connect: ' . mysql_error());
mysql_select_db('YourDatabaseName') or die('Could not select database');
$query = "SELECT * FROM scores ORDER by `score` DESC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
echo ($i + 1)." ";
$row = mysql_fetch_array($result);
echo $row['name'] . "\t" . $row['score'] . "\n";
echo "<div>\n";
}
?>
</p>
So with this you should have no problems getting started displaying the unify serverside high scores on your web page! good luck!
Hope this saves a few people the effort of having to dig into PHP a little to get this going. Aside from making it skip a line after displaying info, and numbering each result, this is basically the same as how the game would retrieve scores, and its unlimited. I suppose if you had TONS of entries, you might want to limit it to like 100 or so top scores. This could be accomplished I think, by using LIMIT 100 in this line like so:
$query = "SELECT * FROM scores ORDER by `score` DESC LIMIT 100";
@$$anonymous$$DReptile Good stuff! One of these days im gonna put this to use bookmarked.
@hijinxbassist no problemo, I ask a lot of the answers, so I must give back haha
Your answer
Follow this Question
Related Questions
Live chat using MySQL? 0 Answers
PHP HighScore Position 1 Answer
Adding extra information to Server Side Highscores 4 Answers
Android build, wwwform gives ssl.SSLHandshakeException 1 Answer