SQL to PHP to Unity, How to separate variables

So below is the code that I’m using to retrieve data from mySQL database but the problem is I get all the columns as one string. Is there any way to get the data as separate variables??

function getScores(UserID, Level, CheckpointsArray) {

    hs_get = WWW(highscoreUrl);
    yield hs_get;
    
    if(hs_get.error) {
        print("There was an error loading data: " + hs_get.error);
    } else {
	
		print(hs_get.text);
    }

can you post the result of hs_get.text?

JSON, then parse the string.

I build an array in php with column name as key and then convert it to JSON. Then I parse the string in c# with regex and re-assing the values to members in a class that maps the table.

MisterB, yes, I just get all the values from the database like for an example:
262839 9 something1,something2
758594 3 something6, something7

The first set of numbers being the UserID, the second the Level the last being the Checkpoints. I get the output as exactly as I’ve written it, just a string with a bunch of spaces every row in a new line.
If you’re wondering what my PHP code looks like:

$Level = mysql_real_escape_string($_GET['Level'], $db);
$CheckpointsArray = mysql_real_escape_string($_GET['CheckpointsArray'], $db);
         
$query = "INSERT INTO `RSG_SaveData`(`UserID`, `Level`, `CheckpointsArray`) VALUES('$user_id', '$Level', '$CheckpointsArray')"; 
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

Scarpelius, that’s quite a brilliant idea, I think I know how to get the stuff into an array to convert it to JSON but not sure how to parse it :frowning:

public Someclassname : MonoBehaviour
{
...
    [HideInInspector]
    public List<UserRow> userRows = new List<UserRow>();

    private void ParseJSON(string json)
    {
        foreach (Match match in Regex.Matches(json, @"{(.*?)}"))
        {
            userRows.Add(new userRow(match.Groups[1].Value));
        }
    }
...
}
public class UserRow
{
    public int id;
    public string name;
    public string email;
    public int age;

    public UserRow(string row)
    {
        foreach (Match match in Regex.Matches(row, @"""(.*?)"":""(.*?)"""))
        {
            switch (match.Groups[1].Value)
            {
                case "id":
                    this.id = Convert.ToInt32(match.Groups[2].Value);
                    break;
                case "name":
                    this.name = Convert.ToString(match.Groups[2].Value);
                    break;
                case "email":
                    this.email = Convert.ToString(match.Groups[2].Value);
                    break;
                case "age":
                    this.age = Convert.ToInt32(match.Groups[2].Value);
                    break;
                default:
                    break;
            }
        }
    }
}

Oh wow thanks, I will try this out :slight_smile: Cheers!