Best way to use data from MySQL in Construct 2

Get help using Construct 2

Post » Sun Mar 12, 2017 11:03 pm

I am making a quiz game and I'm making an admin page where users may add new questions. Therefore a MySQL database is the best way to do it for me.

Now I have a table for questions and another one for answers. Like this:
tblQuestions
questionID
question
level (the level of the question from 1-3)

tblAnswers
answerID
answer
correct (true/false for correct answer)
questionID (the id for the question that the answer belongs to)

What is the best (suggested) way to get these datas into Construct 2? Create a dynamic xml file from php? Import data into an array with AJAX?

I made a static XML to try, and it worked fine, but as I wrote I need a dynamic way to get data from MySQL.
Image
B
14
S
4
Posts: 145
Reputation: 1,943

Post » Sun Mar 12, 2017 11:27 pm

I use php (and AJAX)) to read and write to a MySQL database. There are tutorials that helped me get started.
My php script builds a big string of records to send all at once, that I then parse in C2 using tokenat.
The only part that was slightly tricky was figuring out that I had to urlencode the data to avoid trouble. And to escape and urlencode the data being sent back to write...
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Mon Mar 13, 2017 12:07 am

AllanR wrote:I use php (and AJAX)) to read and write to a MySQL database. There are tutorials that helped me get started.
My php script builds a big string of records to send all at once, that I then parse in C2 using tokenat.
The only part that was slightly tricky was figuring out that I had to urlencode the data to avoid trouble. And to escape and urlencode the data being sent back to write...


Yeah, I watched some of those examples, but I will need a more advanced method than those I've seen since I need to use a multidimensional array.
Image
B
14
S
4
Posts: 145
Reputation: 1,943

Post » Fri Apr 21, 2017 2:26 pm

AllanR, what php/MySQL tutorials did you find to be the most helpful? I'm a newbie and need to ramp up on this pretty quickly. Thx, Jefferson
B
24
S
10
G
1
Posts: 43
Reputation: 2,288

Post » Fri Apr 21, 2017 2:27 pm

Jalindso, same above question for you, if you don't min weighing in...
Jefferson
B
24
S
10
G
1
Posts: 43
Reputation: 2,288

Post » Fri Apr 21, 2017 5:42 pm

janlindso wrote:I made a static XML to try, and it worked fine, but as I wrote I need a dynamic way to get data from MySQL.


Nothing stops you from building a dynamic XML file from your PHP script. A DOMDocument should work wonders for this.

See the docs here : http://it.php.net/manual/en/book.dom.php

Once the document is finished, you can output it as an XML string using DOMDocument::saveXML.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Wed May 24, 2017 8:20 pm

I ended up with creating a dynamic XML from PHP. Then I imported it from URL.
Image
B
14
S
4
Posts: 145
Reputation: 1,943


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests