Saving Data (please help)
I am doing a data draw that brings the data from a MySQL database and I want to save the winners in a list of text or excel to be able to print (the part of saving the list is the problem)
this is my game, so the first data is the id top right corner, then is the name, the bill and the ruc number. in the console it display the random data and it displays just one and i want to save that one winner o a list of winners, my idea was when inputkeydown raffle names and inputkeyup save that name. here is my DataLoader script: using System; using System.Collections; using UnityEngine; using UnityEngine.UI; using System.IO;
public class DataLoader : MonoBehaviour
{
public Text id;
public string ID = "id:";
public Text factura;
public string NFA = "factura:";
public Text ruc;
public string NRU = "ruc:";
public Text nombre;
public string NOM = "nombre:";
public string[] items;
void Update()
{
if (Input.GetKeyDown(KeyCode.B))
StartCoroutine("Start");
}
IEnumerator Start()
{
WWW coneccion = new WWW("http://localhost/trivia/getdatos.php");
yield return (coneccion);
if (Input.GetKey(KeyCode.B))
{
WWW getdatos = new WWW("http://localhost/trivia/getdatos.php");
yield return getdatos;
string getdatosString = getdatos.text;
print(getdatosString);
items = getdatosString.Split('@');
print(GetDataValue(items[0], "id:"));
id.text = "id: " + GetDataValue(items[0], "id:");
print(getdatosString);
items = getdatosString.Split('~');
print(GetDataValue(items[0], "factura:"));
factura.text = "factura: " + GetDataValue(items[0], "factura:");
print(getdatosString);
items = getdatosString.Split('`');
print(GetDataValue(items[0], "ruc:"));
ruc.text = "ruc: " + GetDataValue(items[0], "ruc:");
print(getdatosString);
items = getdatosString.Split('!');
print(GetDataValue(items[0], "nombre:"));
nombre.text = "nombre: " + GetDataValue(items[0], "nombre:");
}
}
string GetDataValue(string data, string index)
{
string value = data.Substring(data.IndexOf(index) +index.Length);
if(value.Contains("~"))value = value.Remove(value.IndexOf("~"));
return value;
}
/*public void SaveToFile()
{
}*/
}
and this is my php getdatos script:
<?php
$servidor = 'localhost';
$user = 'root';
$password = '';
$baseDatos = 'trivia';
$conexion = new mysqli($servidor, $user, $password, $baseDatos);
if (!$conexion)
{
echo "400";
}
else
{
$sql = "SELECT * FROM usuarios ORDER BY RAND() LIMIT 1";
$resultado = mysqli_query($conexion, $sql);
if (mysqli_num_rows($resultado)>0)
{
while ($row = mysqli_fetch_assoc($resultado)){
echo "id:".$row['id']."@" ."factura:".$row['factura']."~" . "ruc:".$row['ruc']. "`" .
"nombre:".$row['nombre']. "!";
}
}
}
?>
and this is my useless FileWrite script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class FileWrite : MonoBehaviour
{
string writePath;
public string GetDataValue(string data, string index);
public List<string> writeList = new List<string>();
// Use this for initialization
void Start ()
{
writePath = Application.dataPath + "/TestFile.txt";
WriteFile(writePath);
}
void Update()
{
if (Input.GetKeyUp(KeyCode.B))
GetDataValue.writeList;
}
void WriteFile(string filePath)
{
StreamWriter sWriter;
if (!File.Exists(filePath))
{
sWriter = File.CreateText(Application.dataPath + "/TestFile.txt");
}
else
{
sWriter = new StreamWriter(filePath);
}
for (int k = 0; k < writeList.Count; k++)
{
sWriter.WriteLine(writeList[k]);
}
sWriter.Close();
}
}
PLEASE HELP! any coment or solution is welcome!
can you post the output of this line :
print(getdatosString);
please
Your answer
Follow this Question
Related Questions
The laser problems 0 Answers
Big numbers 2 Answers
How to call an override function if it was overrode. If not, just call the parent's function 2 Answers
How can i scale a cube from one side only on x only ? 2 Answers
How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers