C# 从高分板添加和显示新统计信息
现在我已经将我的高分板保存为一个SQL数据库,我正在使用一些PHP脚本通过Unity访问该数据库。我原来的记分板允许我存储用户名和他们的分数,但我试图添加额外的字段,如准确性等。然而,我的新字段没有显示或传递到我的服务器 我有两个PHP脚本,分别是display.PHP和addscrore.PHP(拼写错误我会纠正)。Display.php如下所示:C# 从高分板添加和显示新统计信息,c#,php,C#,Php,现在我已经将我的高分板保存为一个SQL数据库,我正在使用一些PHP脚本通过Unity访问该数据库。我原来的记分板允许我存储用户名和他们的分数,但我试图添加额外的字段,如准确性等。然而,我的新字段没有显示或传递到我的服务器 我有两个PHP脚本,分别是display.PHP和addscrore.PHP(拼写错误我会纠正)。Display.php如下所示: <?php // Send variables for the MySQL database class. $database = mysq
<?php
// Send variables for the MySQL database class.
$database = mysql_connect('localhost', 'dark', 'dark') or die('Could not connect: ' . mysql_error());
mysql_select_db('dark') or die('Could not select database');
$query = "SELECT * FROM `scores` 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'] . "\t" . $row['score'] . "\t" . $row['accuracy'] . "\n";
}
?>
然后,当我想向表中添加一些新信息时,我调用以下代码行:
string name = "Rawr";
int score = 1325;
float accuracy = 40.0f;
HSController _test;
// Use this for initialization
void Start()
{
_test = new HSController();
StartCoroutine(_test.PostScores(name, score,accuracy));
}
然而,所有这些,我的新领域,准确性,仍然没有被显示。有人能看出我做错了什么,以及为什么我调用新字段时没有显示它吗?可能根本不是原因,但在C#中,当您构建帖子URL时,您缺少了一个等号
“&accurity”
using UnityEngine;
using System.Collections;
public class HSController : MonoBehaviour
{
private string secretKey = "mySecretKey"; // Edit this value and make sure it's the same as the one stored on the server
public string addScoreURL = "/score/addscrore.php?"; //be sure to add a ? to your url
public string highscoreURL = "highscoretable/display.php";
void Start()
{
StartCoroutine(GetScores());
}
// remember to use StartCoroutine when calling this function!
public IEnumerator PostScores(string name, int score, float accuracy)
{
//This connects to a server side php script that will add the name and score to a MySQL DB.
// Supply it with a string representing the players name and the players score.
string hash = MD5.Md5Sum(name + score + accuracy + secretKey);
string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&accuracy" + accuracy + "&hash=" + hash;
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
if (hs_post.error != null)
{
print("There was an error posting the high score: " + hs_post.error);
}
}
// Get the scores from the MySQL DB to display in a GUIText.
// remember to use StartCoroutine when calling this function!
public IEnumerator GetScores()
{
gameObject.guiText.text = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);
yield return hs_get;
if (hs_get.error != null)
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
}
string name = "Rawr";
int score = 1325;
float accuracy = 40.0f;
HSController _test;
// Use this for initialization
void Start()
{
_test = new HSController();
StartCoroutine(_test.PostScores(name, score,accuracy));
}