I am currently trying to build a dashboard on my Node.js project. To get an overview of certain values, they should be summed up. My SELECT works fine in my MySQL database, but if I include it in my Node project then I will not get any output.
app.get('/dash', function(req, res, next) {
connection.query("SELECT SUM(g_speicherplatz), SUM(g_spielzeit), SUM(g_kosten) FROM games", function(error, result, fields) {
if(error) {
req.flash('error', error)
res.render('games/g-dash', {
data: ''
})
} else {
res.render('games/g-dash', {
data: result,
})
}
})
})
EJS Output:
<div class="container">
<div class="row">
<% if (data) {
console.log("Anzahl Datensätze: " + data.length);
data.forEach(function(dash){ %>
<div class="card mb-3">
<h3 class="card-header">Statistiken</h3>
<h3><%= dash.g_speicherplatz %></h3>
<h3><%= dash.g_spielzeit %></h3>
<h3><%= dash.g_kosten %></h3>
</div>
<% }) %>
<% } %>
</div>
</div>
Where is my mistake?