first time posting, hopefully this will be helpful to others too. I’ve found a few posts on this topic but it appears I’m having quite a specific problem.
This is my output in PHP
questions=The ‘Sea Swallow’ is an alternative name for which bird?/In which sport would you see a ‘Western Roll’?/Who is better known as ‘Herbert Khaury’?/’Diet’ is the parliament of which country?/What is the real first name of Coco Chanel?/’The Aztecs’ were natives of which country?/What was invented by‘O.A. North’ in 1869?/King Zog was the ruler of which country?&answers=Seagull/Penguin/Tern/Cormorant&correct=0/0/1/0&
And this is my AS3 code
var request:URLRequest = new
URLRequest("http://localhost:8888/Quiz/questions.php");
request.method = URLRequestMethod.GET;
var loader2:URLLoader = new URLLoader();
loader2.addEventListener(Event.COMPLETE, completeHandler);
loader2.dataFormat = URLLoaderDataFormat.TEXT;
loader2.load(request);
function completeHandler(event:Event) :void{
var questions1 = event.target.data.questions1;
// dynamic text box called username
questionbox.question.text=event.target.data.questionbox.question.text;
}
var questions:String;
var questionsArray:Array=questions.split("/");
I’m trying to get the question to appear in a dynamic text box,but am receiving the error code #2007 Parameter text must be non-null.
I’m effectively trying to turn my string into an array.
Can anybody see the problem here?
Any help would be greatly appreciated! Thanks in advance
EDIT:
This is my PHP code
<?php
//functions
function get_id($column, $table)
{
$sql = mysql_query("select $column FROM $table") ;
while ($row =mysql_fetch_array($sql))
{
return $row["ID"];
}
}
function getquestions($id)
{
$sql =mysql_query("select text FROM questions WHERE quiz_ID =$id ");
$questions = array();
while($row = mysql_fetch_row($sql))
{
$questions[] = $row[0];
}
return $questions;
}
function getanswers($id)
{
$sql = mysql_query("select answer FROM answers WHERE question_ID= $id ");
$answers = array();
while($row =mysql_fetch_row($sql))
{
$answers[] = $row[0];
}
return $answers;
}
function getcorrect($id)
{
$sql = mysql_query("SELECT correct FROM answers WHERE question_ID= $id ");
$correct =array();
while($row =mysql_fetch_assoc($sql))
{
$correct[] =$row["correct"];
}
return $correct;
}
//Connect to Database
$con = mysql_connect("localhost","dinita","3nd3m0luk");
if(!$con)
{
die('Could not connect: '.mysql_error());
}
else
{
// SELECT DATABASE
mysql_select_db("quizCreation", $con);
// Create an array of data from database
$quizid = get_id("ID","quizName");
$questionid = get_id("ID", "questions");
$ques = implode("/",getquestions($quizid));
$ans =implode("/",getanswers($questionid));
$cor =implode("/", getcorrect($questionid));
echo htmlentities( "questions"."=". $ques."&");
echo htmlentities("answers"."=".$ans."&");
echo htmlentities("correct"."=".$cor."&");
}
mysql_close($con);
?>
If that is the output of your php code, then if you have to visualize it in the textield, you should change it like this:
And if you want to convert the String as an Array, then do like this: