mysql - How to obtain value from inner request. Function return undefined -


i'm trying quiz table quizzes , after obtaining trying array of answers table questions. doesn't work

i send questiondto(json) this.add method, question i've added in table , need add answers ,

var question = require('../models/question');  function quiz() {   this.getbyid = function(quizid,res) {     connection.acquire(function(err, con) {       con.query('select * quizes `id` = ? ', quizid,    function(err, result) {         con.release();         result.questions = question.getallbyquizid(quizid);         res.send(result);       });     });   }; 

question.getallbyquizid(quizid); has return array of questions. here implementation

function question() {    this.getallbyquizid = function(quizid) {     return connection.acquire(function(err, con) {       return con.query('select * questions `quizid` = ? ', quizid, function(err, rows) {         if (err) throw err;          con.release();          console.log(json.parse(json.stringify(rows)));         return json.parse(json.stringify(rows));       });     });   }; 

console.log() returns applicable value function return undefined

i have wasted hours tackle. still can't :(

you should pass callback handle instead of 'return' has asynchronous block in function.

var question = require('../models/question');  function quiz() {   this.getbyid = function(quizid,res) {     connection.acquire(function(err, con) {       con.query('select * quizes `id` = ? ', quizid,    function(err, result) {         con.release();         question.getallbyquizid(quizid, function(err, data){            if(err) {               throw err;            } else {               result.questions = data;               res.send(result);            }         });       });     });   };  function question() {    this.getallbyquizid = function(quizid, callback) {      connection.acquire(function(err, con) {        con.query('select * questions `quizid` = ? ', quizid, function(err, rows) {         if (err) callback(err);          con.release();          console.log(json.parse(json.stringify(rows)));         callback(null, json.parse(json.stringify(rows)));       });     });   }; 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -