- Home /
Yield return tables selectable with mysql data
Hallo i am new in unity and i have searched all over inernet for answears. I am trying to make a selectable list that retrieves and stores data on mamp with php and mysql form using c#. I am trying to receive data and display it properly but with my return i get a window showing code first and after that the data stored that i want to display. I want to make it with an foreach statement to show up like scrolable list that i can select one. Any help appriciated. Thank you.
using UnityEngine; using System.Collections; using UnityEngine.UI; public class LatestTech : MonoBehaviour { string answer; Vector2 position; private Rect windowRect = new Rect(530, 100, Screen.width/3, Screen.height/2); public string Name; public string Surname; public string Address; public string Phone; public string[] top10Techs; public string db_url="http://localhost/";
void OnGUI(){ windowRect = GUI.Window(0, windowRect, DoMyWindow, "Τεχνικοι"); Name = GUI.TextField(new Rect(305, 240, 200, 20), Name, 25); Surname = GUI.TextField(new Rect(305, 290, 200, 20), Surname, 25); Address = GUI.TextField(new Rect(305, 340, 200, 20), Address, 25); Phone = GUI.TextField(new Rect(305, 390, 200, 20), Phone, 25);
if (GUI.Button (new Rect (303, 170, 215, 30), "Click here to add")) {
StartCoroutine (SaveScoress ()); }
if (GUI.Button (new Rect (303, 110, 215, 30), "Click here to display")) {
WWW get_www = new WWW(db_url);
StartCoroutine (LoadScoress ());
}
}
void DoMyWindow(int windowID) { position = GUILayout.BeginScrollView(position); GUILayout.Label(answer); GUILayout.EndScrollView();
}
IEnumerator SaveScoress() { // first we create a new WWWForm, that means a "post" command goes out to our database (for futher information just google "post" and "get" commands for html/php WWWForm form = new WWWForm ();
// with this line we will give a new name and save our score into that name
// those "" indicate a string and attach the score after the comma to it
form.AddField ("newName", Name);
form.AddField ("newSurname", Surname);
form.AddField ("newAddress", Address);
form.AddField ("newPhone", Phone);
// the next line will start our php file that saves the Score and attaches the saved values from the "form" to it
// For this tutorial I've used a new variable "db_url" that stores the path
WWW webRequest = new WWW (db_url + "SaveScore.php", form);
// with this line we'll wait until we get an info back
yield return webRequest;
print("Success on Ienum save");
}
IEnumerator LoadScoress()
{
// we don't need to store any variable in this, just run the php file
WWW webRequest = new WWW(db_url + "LoadScores.php");
// now we wait again for the feedback of the command
yield return webRequest;
// this is a GUIText that will display the scores in game.
//gameObject.GetComponent<Text>().text = "" + webRequest.text;
print("Success on Ienum Load");
answer = webRequest.text.ToString();
}
}