J450n Posted December 14, 2019 Share Posted December 14, 2019 (edited) I am trying to get my database entry's to C# in Unity to display them. This formatting works echo ("|".$row['GUID']. PHP_EOL. "|".$row['userName']. PHP_EOL. "|".$row['health']. PHP_EOL. "|".$row['level']. PHP_EOL. "|".$row['points']. PHP_EOL. "|".$row['killBonus']. PHP_EOL. "|".$row['killRate']. PHP_EOL. "|".$row['kills']. PHP_EOL. "|".$row['misses']. PHP_EOL. ";"); But When I get it into Unity using this code string Data_string = www.downloadHandler.text; string[] DataArray; DataArray = Data_string.Split('|'); //Debug.Log(DataArray); string guid = (DataArray[0]); Debug.Log(guid); string username = (DataArray[1]); Debug.Log(username); int health = System.Convert.ToInt32(DataArray[2]); Debug.Log(health); int level = System.Convert.ToInt32(DataArray[3]); Debug.Log(level); int points = System.Convert.ToInt32(DataArray[4]); Debug.Log(points); int killBonus = System.Convert.ToInt32(DataArray[5]); Debug.Log(killBonus); float killRate = float.Parse(DataArray[6]); Debug.Log(killRate); float kills = float.Parse(DataArray[7]); Debug.Log(kills); float misses = float.Parse(DataArray[8]); Debug.Log(misses); It puts out the first string "GUID" but then throws an error before "username". Can someone help me understand what I am doing wrong? This is the error I am getting. FormatException: Input string was not in a correct format. System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) System.Int32.Parse (System.String s, System.IFormatProvider provider) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) System.Convert.ToInt32 (System.String value) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0) Login+<LoginCalled>d__4.MoveNext () (at Assets/CODE/Login.cs:52) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) Edited December 14, 2019 by J450n Quote Link to comment https://forums.phpfreaks.com/topic/309682-database-rsults-formatting/ Share on other sites More sharing options...
Barand Posted December 14, 2019 Share Posted December 14, 2019 If you are splitting on "|", why put the PHP_EOLs in there? Also, try omitting the leading "|" in your string, so you have guid|username|health|...|misses When you split that on "|" the guid should be item 0. With the leading "|" (i.e "| guid | username | …") I would expect item 0 to be blank after the split and guid would be item 1.. Quote Link to comment https://forums.phpfreaks.com/topic/309682-database-rsults-formatting/#findComment-1572515 Share on other sites More sharing options...
J450n Posted December 14, 2019 Author Share Posted December 14, 2019 After posting this I tried this; echo (" ".$row['GUID']. " ".$row['userName']. " ".$row['health']. " ".$row['level']. " ".$row['points']. " ".$row['killBonus']. " ".$row['killRate']. " ".$row['kills']. " ".$row['misses']. ";"); and I got the same result. So do I treat the " " to be an item as well when placing the [number of item] in the C# code? Quote Link to comment https://forums.phpfreaks.com/topic/309682-database-rsults-formatting/#findComment-1572516 Share on other sites More sharing options...
Barand Posted December 14, 2019 Share Posted December 14, 2019 You have taken the "|" characters out! How do expect to split it? The echoed string should look like guid|username|health|...|misses I.E. $row = [ 'guid' => 'xyz', 'username' => 'fred', 'health' => 1, 'level' => 42 ]; echo $row['guid'] . '|' . $row['username'] . '|' . $row['health'] . '|' . $row['level']; or (easier if you want every $row item in their natural ORDER) echo join('|', $row); Then when you split it, the array will look like Array ( [0] => xyz [1] => fred [2] => 1 [3] => 42 ) Quote Link to comment https://forums.phpfreaks.com/topic/309682-database-rsults-formatting/#findComment-1572518 Share on other sites More sharing options...
J450n Posted December 14, 2019 Author Share Posted December 14, 2019 I changed the echo to this echo $row['GUID'] . '|' . $row['userName']. '|' .$row['health']. '|' .$row['level']. '|' .$row['points']. '|' .$row['killBonus']. '|' .$row['killRate']. '|' .$row['kills']. '|' .$row['misses']; And it works perfectly. I knew there was some formatting of the echo that was screwing me up. Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/309682-database-rsults-formatting/#findComment-1572519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.