Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:53:07+00:00 2026-05-24T09:53:07+00:00

Simple newbie question, I am starting out with nodejs, and I am pretty new

  • 0

Simple newbie question, I am starting out with nodejs, and I am pretty new to backend languages in general.

I managed to publish a single field from a database to a webpage using the default jade engine in express-js.

/**
 * 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);

My question is, how can I show a list of all the elements retrieved by theMySQL Query?

Thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:53:07+00:00Added an answer on May 24, 2026 at 9:53 am

    Like this. Results is an array so you have to loop over it

        for (var i in results){
             var sqlResult = results[i];
             console.log(sqlResult['text'], sqlResult['title']);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this newbie question, just got starting. I want a simple program to
This is a pretty simple question: as a Git newbie I was wondering if
A pretty newbie question as I rarely work with XML. I'm trying out writing
This is a real newbie question. I have simple app that selects a picture
Just a simple question from a relative Java newbie: what is the difference between
A question for all the GWT gurus out there. I'm a newbie in GWT
Newbie question. I've created a very simple LoginForm class in symfony. It checks if
Here goes a newbie question: Create a new project in Xcode: File > New
I'm sure that this is a simple newbie question, but the answer is eluding
Newbie question: I am making a simple html game. It consists of these DIV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.