I have this snippet that counts the number rows and returns the number of rows found in a MySQL table. This is the code, in which I have used underscore.js's _.each
to iterate.
var all_rows = Noder.query('SELECT count(*) as erow from crud ', function(err, the_rows) {
_.each(the_rows, function (corndog) {
var trows = corndog.erow;
console.log("All rows", trows);
});
// var das_rows = trows;
// var total_pages = Math.ceil(das_rows / per_page);
// console.log("Pages",total_pages);
res.view('noder/orm', {
layout: 'layout',
js:the_rows,
post:results,
title: 'This is the hi page title. Gandalf The great.'
});
});
I want to use trows
to calculate the number of pages are to be created for my paging code. However, I cannot access the variable trows
.
This is the output of console.log(the_rows);
[ RowDataPacket { erow: 12 } ]
Is there another way I can do this to make trows
available to the rest of my code?