Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. {"questionario":[{"id_base":"609","id_usuario":"1","id_pesquisa":"1","id_varejo":"16","respostas":"[{"Pergunta":"Nome","Resposta":"asdasd"},{"Pergunta":"Você é responsável pelo recebimento da entrega de parceria ?","Resposta":"não"}]","data_inicio":"2018-04-20 16:56:58"}]}
  2.  
  3. public function saveResult($post) {
  4.  
  5. $array = $post;
  6.  
  7. foreach ($array['questionario'] as $value) {
  8. $ar['id_usuario'] = $value['id_usuario'];
  9. $ar['id_pesquisa'] = $value['id_pesquisa'];
  10. $ar['id_varejo'] = $value['id_varejo'];
  11. $ar['id_base'] = $value['id_base'];
  12. $ar['data_inicio'] = $value['data_inicio'];
  13. foreach($value['respostas'] as $value){
  14. $ar['Pergunta'] = $value['Pergunta'];
  15. $ar['Resposta'] = $value['Resposta'];
  16. try{
  17. $db = Database::conexao();
  18. $qry = "INSERT INTO `resultado`(`id_pesquisa`,`id_varejo`,`id_usuario`,`id_base`,`pergunta`,`resposta`,`data_inicio`)VALUES(
  19. :idPesquisa,
  20. :idVarejo,
  21. :iduser,
  22. :idbase,
  23. :pergunta,
  24. :resposta,
  25. :data_inicio)";
  26.  
  27. $statement = $db->prepare($qry);
  28. $statement->bindValue(':idPesquisa', $value['id_pesquisa']);
  29. $statement->bindValue(':idVarejo', $value['id_varejo']);
  30. $statement->bindValue(':iduser', $value['id_usuario']);
  31. $statement->bindValue(':idbase', $value['id_base']);
  32. $statement->bindValue(':pergunta', $value['Pergunta']);
  33. $statement->bindValue(':resposta', $value['Resposta']);
  34. $statement->bindValue(':data_inicio', $value['data_inicio']);
  35. $statement->execute();
  36.  
  37. } catch (PDOException $e){
  38. echo $e->getMessage();
  39. $db->rollBack();
  40. }
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment