node.js - Get MySQL data using express ejs -
i want data mysql in express ejs. getting data way.
connection.query( 'select * wp_postmeta meta_id = 294', function(err, homeadjust) { var homeadjust = json.stringify(homeadjust); return res.render('index', {homeadjust : homeadjust});
and in ejs file below:
<% json.parse( homeadjust ).foreach(function(items){ %> <h3><%= items.meta_value %></h3> <% }); %>
but there way data form mysql white single query this:
connection.query( 'select * wp_postmeta', function(err, testimonials) { var testimonials = json.stringify(testimonials); return res.render('index', {testimonials : testimonials});
and use in ejs file '.' separation or other , thing this
<% json.parse(testimonials).meta_key.author_description.foreach(function(item){ %> <% }); %>
if appreciated.
i don't know you're tying do, testimonials
should returned array, objects inside:
so
connection.query( 'select * wp_postmeta', function(err, testimonials) { return res.render('index', {data : testimonials}); <% (var = 0; < data.length; i++) { %> <li><% data[i].testimonial %></li> <% } %>
Comments
Post a Comment