0

Am trying to access the value of 'i' in the db query below but unfortunately, because the result of the query is one, am only getting the first value of the looping instead of getting the entire looping values. Any help. Thanks

for (var i = 0; i < 5; i++) {
      db('student_balance').where({'student_number':student_number}).then(function(pfb_row){
         for (var b = 0; b < pfb_row.length; b++) {
              pfb_row[b];
             }
        console.log(i)
       });
    }
ASM
  • 169
  • 3
  • 12
  • asynchronous code isn't synchronous – Jaromanda X Mar 04 '17 at 07:57
  • I suggest you to debug e.g. `node --inspect app.js` and put breakpoints on both for loop statements and console.log to understand flow of your code. As @JaromandaX pointed, you are mixing sync and async code. – Sangharsh Mar 04 '17 at 08:00
  • for performance reasons I would suggest using a query with $in e.g. `{ 'student_number': { $in: [1, 2, 3]} }` – Nico Van Belle Mar 04 '17 at 08:16

0 Answers0