Hi all,
so i am trying to get the values from my sqli/ php array into variables in unity. i know the php works as the debug.log is correct. how do i assign these to a variable which i can attatch to ui components in the game?
code is as follows.
php:
<?php
session_start();
include 'dbconnect.php';
$output = array();
$answer_array = array('answerA','answerB','answerC','answerD'); //loads answers into array
$query = ("select * from questiontable ORDER BY RAND () LIMIT 1 ");//sql query to get questions
$result =mysqli_query($conn, $query) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)){
$row_cnt = mysqli_num_rows($result);
$output['question']=$row['question'];
$query2 = ("select * from answerTable where questionId = '". ($row ['questionId'])."' order by rand()");//sql query to get answers for questions by questionId
$result2 =mysqli_query($conn, $query2) or die(mysqli_error($conn));
$i=0;
$question=$row ['question'];
while ($row2 = mysqli_fetch_assoc($result2)){
$output[$answer_array[$i]]=$row2['answer'];
$i++;
$_POST = $output;
}
}
echo "
";
echo $_POST ['question'];
echo "
";
echo $_POST['answerA'];
echo "
";
echo $_POST['answerB'];
echo "
";
echo $_POST['answerC'];
echo "
";
echo $_POST['answerD'];
?>
and the C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class qNaDisplay : MonoBehaviour {
public Text questDisp, ansA, ansB, ansC, ansD;
private string questdispText, ansAdisp, ansBdisp, ansCdisp, ansDdisp;
// Use this for initialization
void Start ()
{
WWW questionURL = new WWW("http://localhost:8080/Project/PHP/questionRequest.php");
StartCoroutine(qNaget(questionURL));
}
// Update is called once per frame
void Update () {
}
private IEnumerator qNaget (WWW questionURL)
{
yield return questionURL;
if (questionURL.error != null)
{
print("There was an error getting the question " + questionURL.error);
}
else
{
Debug.Log(questionURL.text);
}
}
}
and this is the result in debug. log…
Connected successfully
Which is spelled correctly?
carriges
carriages
carryges
carridges
UnityEngine.Debug:Log(Object)
c__Iterator0:MoveNext() (at Assets/scripts/qNaDisplay.cs:37)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
any help is appreciated.