- Home /
Retrieving and dissecting MYSQL data from WWW
I am having troubles dissecting the data that I receive from my database through PHP. Basically what I want to do is after I have received the data, I want to assign each row to their respective variables in a for loop until they are all in a variable. In PHP, this can be easily done through:
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo $row['item_ID'];
echo $row['item_name'];
}
}
But I have no idea how this can be done through unity using WWW or some other means. I am assuming I have to use WWW.data?
Answer by Graham-Dunnett · Jan 04, 2015 at 05:18 PM
Use WWW
to talk to your server and have your PHP talk to the MySQL database and retrieve the data.
Thank you for replying but I'm asking how to assign the data that I have retrieved into a temporary string/int variable. Like for example, the data I receive are 'item_ID' and 'item_name'. I want to connect 'item_ID' and 'item_name' to 'int received_ID' and 'string received_name' separately and Debug.Log them in a for loop because I will be expecting to receive multiple 'item_ID' and 'item_Name' datas
For example:
for(int x=0;x<data.column.size;x++){
int received_ID = data['item_ID'];
string received_Name = data['item_name'];
Debug.Log(received_ID + received_name);
}
You'd want to format your php output in a specific way. For instance json or xml style.
But if it stays that simple (one item one itemId), you could also simply use an , or something like this as an indicator on where to split the string you retrieve from PHP. Then you can use split to split it into an array, so you can access it.
If you need to retrieve the Data from multiple Items you should really look into json or xml formatting, as those are pretty common and easy to read/write.
Answer by $$anonymous$$ · May 29, 2018 at 11:20 PM
DID YOU SOLVED YOUR PROBLEM WE ARE HAVING THE SAME ISSUE OR SIMILAR!!
we want Retrieve multiple images from MySql database via Unity C#
we have made it, so we can consult and show in unity with php and c# the data (text) but no the images. the images are transfer in base64, but we can´t transform or show base64 into the image itself.