I am attempting to dynamically populate the dropdown on my template. I am adding company IDs to an array and then attempting to pass the array to the template.
Adding the IDs to the array:
var express = require('express');
//var mysql = require('./dbcon.js');
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 10,
host : 'localhost',
user : 'root',
password: 'Baseball247!',
database: 'award'
});
var app = express();
var handlebars = require('express-handlebars').create({defaultLayout:'main'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', 3000);
app.use(express.static('public'));
app.get('/add-user', function(req,res){
var context = {};
pool.query("SELECT id from company;", function(err,rows,fields){
if (err){
console.log(err);
next(err);
return;
}
context.results = rows;
var companies = [];
//console.log('The solution is: ', rows.length);
for (var i =0; i < rows.length; i++) {
//console.log('The solution is: ', rows[i]["id"]);
companies.push(rows[i]["id"]);
}
console.log(companies);
res.render('addUser', {companies : companies});
});
});
Then, I try to display those values in the dropdown via:
<select>
<% for(var i=0; i < companies.length; i++) { %>
<option><%= companies[i] %></option>
<% } %>
</select>
However, when I look at the web page the dropdown shows this instead of the company IDs:

When I console.log the array I see the correct results so I assume the issue is either with how I am passing the array or how I am traversing/calling the array in the template. Does anyone know what I am missing here?