Hello guys,
I have a php file that echos the data from all the sql table.Here is the code for this
How can i display all these data into unity?
Hello guys,
I have a php file that echos the data from all the sql table.Here is the code for this
How can i display all these data into unity?
Hi,
I use WWW unity API. It’s asynchronous so stick it in a coroutine to check it’s progress:
private IEnumerator GetWebData_Coroutine(string sURL)
{
const int K_NETWORK_TIMEOUT_MILLIS = 20000;//20 secs
StopWatch oStopwatch = new StopWatch();
oStopwatch.Reset();
oStopwatch.Start();
bool bTimedOut = false;
sURL = sURL.Replace(" ", "%20");//MAY NOT NEED THIS FOR PHP
WWW oWWW = new WWW(sURL);
for (;;)
{
if (oWWW.isDone)
{
break;
}
if (oStopwatch.ElapsedMilliseconds > K_NETWORK_TIMEOUT_MILLIS)
{
bTimedOut = true;
break;
}
yield return null;
}
HandleReceivedWebData(oWWW, bTimedOut);
}
If you’re not familiar with coroutines: you start them running like this:
StartCoroutine(GetWebData_Coroutine(sURL));
After it’s downloaded you can get the WWW data how you like it, as a string you would implement a HandleReceivedWebData() function like this for example:
private void HandleReceivedWebData(WWW oWWW, bool bTimedOut)
{
if(bTimedOut)
{
UnityEngine.Debug.LogWarning("TIMED OUT!");
}
else
{
string sText = oWWW.text;
UnityEngine.Debug.Log("RECEIVED=\n" + sText);
// DO SOMETHING WITH TEXT HERE
}
}
Fo more complex transfers I would recommend sticking your server database data into XML or JSON structures (easy in PHP) server side and then echoing that, much easier to parse unity side.
Oh nice!One more question if you know.How can i display ONLY the current user that logged in?In my first scene i have the login-register system and in the second scene i want to display the users stats only.Should i change my php file somehow?
Well you’re gonna have to perform a dbase query that looks up only that users stats.
That users UID needs passing as a PHP parameter in the URL.
I recommend making the UID be seperate to username: your dbase needs unique key column.
P.S.
Etiquette dictates you press “like” or at least say thankyou.
Apologises i haven’t noticed the like button!And yeah i was going to say thank you in the end of cource
Anyways thanks ![]()
Lol, you’re welcome
. Good luck with your project.