Hello! I follow this tutorial closely and understand the jist of it: Server Side Highscores Tutorial. I got it functioning properly but I wish to make it more dynamic. I managed to pass the name of the MySQL table name for posting scores via the addscore.php script, successfully. This is all so I can use this php scripts for multiple tables, related to different games. I tried doing the same for the display.php but for the life of me I can not get it to work!
In my unity C# script I am only able to get a connection by having my URL contain the variable as well (For some reason concenating the URL will cause a 404 error, i.e. URL + "scoreTable=" + scoretable
)
Heres the relative C# code:
public string highscoreURL = "http://website.com/display.php?scoreTable=clicking_game";
IEnumerator GetScores() {
gameObject.guiText.text = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);
yield return hs_get;
gameObject.guiText.text = hs_get.text;
}
And the modified display.php:
<?php
// Send variables for the MySQL database class.
$database = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());
mysql_select_db('my_database') or die('Could not select database');
$scoreTable = $_GET['scoreTable'];
$query = "SELECT * FROM `$scoreTable` ORDER by `score` DESC LIMIT 5";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo $row['name'] . " " . $row['score'] . "
";
}
?>
Just to be extra clear, all I am doing here is changing the ‘scores’ table used in the example to a variable that is passed from unity. This does not work for me however, it says the querey failed because the table does not exist, and the table passed is just ‘’. So connection is being made, and the scoreTable variable is being declared in the PHP script and being used in the querey. But, for some reason my C# code just isn’t passing the string properly. Either that or the PHP script isn’t setting the variable properly.
Any helps or tips would be highly appreciated, thanks!