Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"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"}]}
- public function saveResult($post) {
- $array = $post;
- foreach ($array['questionario'] as $value) {
- $ar['id_usuario'] = $value['id_usuario'];
- $ar['id_pesquisa'] = $value['id_pesquisa'];
- $ar['id_varejo'] = $value['id_varejo'];
- $ar['id_base'] = $value['id_base'];
- $ar['data_inicio'] = $value['data_inicio'];
- foreach($value['respostas'] as $value){
- $ar['Pergunta'] = $value['Pergunta'];
- $ar['Resposta'] = $value['Resposta'];
- try{
- $db = Database::conexao();
- $qry = "INSERT INTO `resultado`(`id_pesquisa`,`id_varejo`,`id_usuario`,`id_base`,`pergunta`,`resposta`,`data_inicio`)VALUES(
- :idPesquisa,
- :idVarejo,
- :iduser,
- :idbase,
- :pergunta,
- :resposta,
- :data_inicio)";
- $statement = $db->prepare($qry);
- $statement->bindValue(':idPesquisa', $value['id_pesquisa']);
- $statement->bindValue(':idVarejo', $value['id_varejo']);
- $statement->bindValue(':iduser', $value['id_usuario']);
- $statement->bindValue(':idbase', $value['id_base']);
- $statement->bindValue(':pergunta', $value['Pergunta']);
- $statement->bindValue(':resposta', $value['Resposta']);
- $statement->bindValue(':data_inicio', $value['data_inicio']);
- $statement->execute();
- } catch (PDOException $e){
- echo $e->getMessage();
- $db->rollBack();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment