Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving all the content of a MySQL query to Jade template engine through NodeJS and Express
    primarykey
    data
    text
    <p>Simple newbie question, I am starting out with nodejs, and I am pretty new to backend languages in general.</p> <p>I managed to publish a single field from a database to a webpage using the default jade engine in express-js.</p> <pre><code>/** * Module dependencies. */ var express = require('express'); var app = module.exports = express.createServer(); var sqlResult; //MySql var mysqlClient = require('mysql').Client, newClient = new mysqlClient(), Database = 'test', Table = 'test_table'; newClient.user ='root'; newClient.password='password'; newClient.connect(console.log('connected to the database.')); newClient.query('USE '+Database); newClient.query( 'SELECT * FROM '+Table, function selectCb(err, results, fields) { if (err) { throw err; } sqlResult = results[0]; console.log(sqlResult['text'], sqlResult['title']); } ); // Configuration app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); app.use(express.session({ secret: 'your secret here' })); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); // Routes app.get('/', function(req, res){ res.render('index', { title: sqlResult['title'] }); }); app.listen(3000); console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); </code></pre> <p>My question is, how can I show a list of all the elements retrieved by theMySQL Query?</p> <p>Thank you :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload