J450n Posted December 18, 2019 Share Posted December 18, 2019 Is there any other way of getting PHP form data into C# any other way besides calling www.downloadHandler.text I am having issues bringing all the entries into C# and breaking them all up. I can do one row fine but multiple rows isn't working. I keep getting an out range error. This is my PHP echo echo $row['userName']. '|' .$row['level']. '|' .$row['points']. '|' .$row['killRate']. '/'; And this is my C# code string nothing = "Not Placed"; string Data_string = www.downloadHandler.text; string[] DataArray; DataArray = Data_string.Split('/'); int numberOfEntries = DataArray.Length; Debug.Log(numberOfEntries); if (DataArray[0] == null || numberOfEntries == 1) { DataArray[0] = nothing; Debug.Log("Data Array [0] isn't there"); High_Points_1.text = DataArray[0]; } else { High_Points_1.text = DataArray[0]; //Debug.Log(DataArray.Length); } if (DataArray[1] == null || numberOfEntries == 2) { DataArray[1] = nothing; Debug.Log("Data Array [1] isn't there"); High_Points_2.text = DataArray[1]; } else { High_Points_2.text = DataArray[1]; //Debug.Log(DataArray.Length); } if (DataArray[2] == null || numberOfEntries == 3) { DataArray[2] = nothing; Debug.Log("Data Array [2] isn't there"); High_Points_3.text = DataArray[2]; } else { High_Points_3.text = DataArray[2]; } if (DataArray[3] == null || numberOfEntries == 4) { DataArray[3] = nothing; Debug.Log("Data Array [3] isn't there"); High_Points_4.text = DataArray[3]; } else { High_Points_4.text = DataArray[3]; } if (DataArray[4] == null || numberOfEntries == 5) { DataArray[4] = nothing; Debug.Log("Data Array [4] isn't there"); High_Points_5.text = DataArray[4]; } else { High_Points_5.text = DataArray[4]; } I have two entries in the database. But when I debugged the number int he array I get 3 strings. I want to show the top five entries in the database. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/ Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 Very confusing. You say you have 2 entries in the database. Then you say you want the top five entries in the database. Your php code only echoes one entry Not surprised you're having problems. 10 minutes ago, J450n said: Is there any other way of getting PHP form data into C# Don't know. This is a PHP forum. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572661 Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 It occurred to me that it might be easier to query for the first 5 records fetchAll() on the result set json encode the array of results then echo the json string. In C#, convert the json back to an array and process. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572662 Share on other sites More sharing options...
J450n Posted December 18, 2019 Author Share Posted December 18, 2019 The database will be have more than five entries. For testing I want to be able to say if there isn't anything there just say this. But my code above isn't working. The PHP code does echo the two entries just like the other issue I had you helped me with. I understand that I only get one string from the echo and the "/" is splitting them apart so I can display them separately. But because there isn't a third, fourth and fifth I am getting the out of bounds error. Can I echo each individual row in the PHP and get it into the C# with more control other than the "www.downloadhandler.text"? Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572663 Share on other sites More sharing options...
J450n Posted December 18, 2019 Author Share Posted December 18, 2019 (edited) 9 minutes ago, Barand said: It occurred to me that it might be easier to query for the first 5 records fetchAll() on the result set json encode the array of results then echo the json string. In C#, convert the json back to an array and process. I tried that but seems like a hassle since I'm using the database and it is handling all the data nicely. If I could just connect to the MySQL database straight with out having the app on the server that would be nice but my host doesn't allow it. And with the Json would need to be split up too Edited December 18, 2019 by J450n Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572664 Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 $res = $conn->query("SELECT username , level , points , killrate FROM atable LIMIT 5; "); $data = $res->fetchAll(); echo json_encode($data); That doesn't look like much of a hassle. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572665 Share on other sites More sharing options...
J450n Posted December 18, 2019 Author Share Posted December 18, 2019 I'm not up to speed enough to tackle Json. I tried to do that route but couldn't get it to work. In that case I wouldn't need a DB, I could just serialize it...but that's out of my comfort zone. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572666 Share on other sites More sharing options...
Barand Posted December 18, 2019 Share Posted December 18, 2019 Forget the json then. This should give you the first 5 records in the format your C# is currently expecting $res = $conn->query("SELECT username , level , points , killrate FROM atable ORDER BY points DESC LIMIT 5; "); $data = []; foreach ($res as $row) { $data[] = join('|', $row); } echo join('/', $data); Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572667 Share on other sites More sharing options...
J450n Posted December 18, 2019 Author Share Posted December 18, 2019 I need to learn this. I built the app and those out of bounds errors are not crashing the app or anything. Is it best practice to not worry about those errors because they will resolve themselves anyway? Thank you. getting into it now. Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572668 Share on other sites More sharing options...
J450n Posted December 19, 2019 Author Share Posted December 19, 2019 4 hours ago, Barand said: Forget the json then. This should give you the first 5 records in the format your C# is currently expecting $res = $conn->query("SELECT username , level , points , killrate FROM atable ORDER BY points DESC LIMIT 5; "); $data = []; foreach ($res as $row) { $data[] = join('|', $row); } echo join('/', $data); @Barand So I get this now. Thank you. It is similar in C#, but I didn't realize I could do this in PHP. Insert other media Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572671 Share on other sites More sharing options...
J450n Posted December 19, 2019 Author Share Posted December 19, 2019 (edited) Now I see how I can split up the individual columns for the rows and to break them up instead of having a string of the row. Thanks again Edited December 19, 2019 by J450n Quote Link to comment https://forums.phpfreaks.com/topic/309714-database-entries-to-c-question/#findComment-1572672 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.