0

Good day everyone!

Basically, my JavaScript knowledge was enough to make a code, which returns a JSON.stringify'ed array to PHP backend using Ajax in this form:

["Test questionnaire.",{"type":"textQuestion","name":"How are you doing?"},{"type":"mapQuestion","name":"Show your favorite location:"},{"type":"selectQuestion","name":"Which one of them is your favorite?","options":["First","second","third"]}]

As you can see, there is a bunch of objects. First one (test questionnaire). Goes into table "questionnaires". Then come the questions. They are connected with foreign key to questionnaires_id and must be added to database as question_type and question_name. If type is selectQuestion, then it also adds the "options" to options table and connects them to related question in questions table.

I understand, that I have to use json_decode to separate the values, i don't understand how to create new rows in mysql database and automatically connect child (question) to parent (questionnaire).

Thank you in advance!

Vlad Šutov
  • 9
  • 1
  • 3
  • Welcome to StackOverflow! We will be glad to help you if you get stuck on a specific programming problem, but we are not here to write code for you. Please see [**How do I ask a good question?**](https://stackoverflow.com/help/how-to-ask) and [**What topics can I ask about here?**](https://stackoverflow.com/help/on-topic). – Alex Howansky Jun 14 '17 at 17:34
  • [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236/1011527) – Jay Blanchard Jun 14 '17 at 17:36
  • Not sure what you mean. I've provided a code i wrote so far, its the PHP part that i'm not familiar with. I can provide the JavaScript code to prove? – Vlad Šutov Jun 14 '17 at 17:36

0 Answers0