www read to variable

hai hai :slight_smile:

im have trouble about insert data from php to variable in c#, i create php and its work perfect then i can read all echo from php, btw this is my c# code.

using UnityEngine;
using System.Collections;

public class item : MonoBehaviour {

    public string[] items;

    // Use this for initialization
    IEnumerator Start ()
    {
        WWW itemData = new WWW ("http://localhost/mmo/item.php");

        

        yield return itemData;

        

        string itemString = itemData.text;
        print (itemString);
        


    }
    

   

}

i not sure about insert every data in my database to variable and call.

for example
in my msql database i have 3 coloum : name, password, email
and get to data to c# use WWW .
then show like this in console:

name:test|password:1234|email:email@email.com|;name:test2|password:1234|email:email2@email.com|;name:test3|password:1234|email:email3@email.com|;

my big question is how call data by name.
example i call name test3 and show password , email.

btw sory for my bad english.

Parsing data like this is a bit of a pain, and the slightest change to the format will break your code, requiring a rewrite. Plus, you’ll probably have to write a new parser function for every. single. type of data you will ever receive. Therefore, if possible, the first thing I would do would be to make the server give the data in a more versatile format, like JSON; then, you can easily use JsonUtility to read it in. If your server were to spit out JSON instead of the format you have currently, all of the code below will be replaced by about two lines of much more readable code. I don’t know what your server code looks like (indeed, I don’t know much PHP myself), but my guess is that there is a handy PHP library that can spit out JSON from a database easily, too.

If you don’t have enough control over the server for that, you can use string.Split to parse your input. Something like this should get you started.

string searchFor = "password";
string[] rows = itemString.Split(";"[0]);
for (int r=0;r<rows;r++) {
string[] cells = rows[r].Split("|"[0]);
for (int c=0;c<cells.Length;c++) {
string[] parts = cells[c].Split(":"[0]);
string key = parts[0];
string value = parts[1];
if (key == searchFor) {
Debug.Log("The password on row "+r+" is "+value);
}
}
}

thanks for idea about pharsing data i will try :slight_smile: