x


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

more ▼

asked Jun 02 '12 at 02:35 AM

MD_Reptile gravatar image

MD_Reptile
281 10 15 19

@MDReptile 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.

Jun 02 '12 at 04:17 AM hijinxbassist

@hijinxbassist Hello again hijinxbassit! You know, actually thats not a half bad idea, I think i will go into my admin view, and see the HTML 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

Jun 02 '12 at 04:21 AM MD_Reptile
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

What you will need to do is this:

  1. Open a blank notepad or similar.
  2. On this notepad, copy the PHP script below.
  3. Change the spots where is says "YourWhatever" to match your database.
  4. 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";
more ▼

answered Jun 03 '12 at 04:57 AM

MD_Reptile gravatar image

MD_Reptile
281 10 15 19

@MDReptile Good stuff! One of these days im gonna put this to use bookmarked.

Jun 03 '12 at 06:12 AM hijinxbassist

@hijinxbassist no problemo, I ask a lot of the answers, so I must give back haha

Jun 03 '12 at 06:16 AM MD_Reptile
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2481
x131
x102
x43
x5

asked: Jun 02 '12 at 02:35 AM

Seen: 558 times

Last Updated: Jun 03 '12 at 06:16 AM