Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver344 · Aug 12, 2011 at 09:12 AM · positionmysqlphphighscores

PHP HighScore Position

Hi,

i would like to find out position of player based on his score via my database. I am succesfuly getting names and scores, tho i dont know how to get players position. As i think i cant send the position in the fetch array. Best would be if i coud send some separate variable. But i dont know how to read separate variables in Unity. It seems to me that i am able to read only one string from one table ?

here is php code:

 $database = mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error());
 mysql_select_db('myscores') or die('Could not select database');
 
    
 $result = mysql_query('SELECT * FROM `scores` ORDER by `score` DESC LIMIT 10', $database);
    
 
 
 while($row = mysql_fetch_array($result))
 {
      echo $row['name']. " ". $row['score']. " ";
 }

I woud like to add something like this :

$playerPosition = mysql_query('SELECT COUNT FROM scores WHERE score > $score');

echo $playerPosition;

tho, i dont know how to read it in Unity and if thast possible. But it seems to me out of place to place it in the loop as i need only once the position.

Thanks for any help

Luke

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MPink · Aug 12, 2011 at 10:35 AM

1st off the query


$playerPosition = mysql_query('SELECT COUNT FROM scores WHERE score > $score');

is in the wrong type of string. You need to use a string with "" marks to have variables placed into them so your query wont work.

2nd im not sure what it would return.


$playerPosition = mysql_query("SELECT COUNT(score) AS Count FROM scores WHERE score > $score");
$row = mysql_fetch_array($playerPosition);
echo $row['Count'];
That should output the position that $score is in your table but my SQL isnt great.
COUNT is an SQL function but im not sure if its any different in MYSQL.

To read a web page in unity ues the WWW class to make the http request.
Watch out for the crossdomain.xml though.
You can make GET or POST requests using WWW so sending the name and receiving the index should be ok.

$database = mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error()); mysql_select_db('myscores') or die('Could not select database');

$result = mysql_query('SELECT * FROM scores ORDER by score DESC LIMIT 10', $database);

$position = 1; while($row = mysql_fetch_array($result)) { if ($row['name']==$_REQUEST['name']) { echo $position; break; } $position++;

} Iv not tested any code just written it.
This should return the position of the 1st score of the player named 'name' in the top 10 scores where name is passed by GET in the url.
http://localhost/getrank.php?name=my_name

Removing 'LIMIT 10' from the query would return the 1st position of the name. If the name is not found nothing will be returned.

w3schools.com/sql Should contain the info you need to formulate a better SQL query.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unify "serverside highscores" - reading in a webpage 1 Answer

Adding extra information to Server Side Highscores 4 Answers

Trying to get server side highscores working with MySQL. Apparently I need a Secret Key for my database. What is that? How do I get one? 1 Answer

Unity CrossDomain.xml Still Required? What is wrong? 0 Answers

Call single function in php from c#? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges