0

I'm running into a issue when trying to display info on my website through a js widget, i'm fairly new to js in general so i cant seem to figure out where the problem lies.

series: [
    var query = connection.query(sql, function(err, result){
      console.log(+ result.length)
    });
    , 0, 0],

here is where its going wrong.

when its saved and i refresh the

var query = connection.query(sql, function(err, result){
      console.log(+ result.length)
    });

is breaking everything and the rest of my JS widgets disappear untill i remove it.

at the top of my js file is where i call the db connect, no where near where im trying to call the result

  var mysql = require('mysql');

var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'testdistress',
    debug: false,
});

console.log("Connected to Mysql");
connection.connect();

var sql = "SELECT * FROM offers";

When i tested it in the node.js console everything worked fine.. it gave me back everything i needed. where am i going wrong?

1 Answer 1

1

Your code for series is incorrect.

series: [
var query = connection.query(sql, function(err, result){
  console.log(+ result.length)
});
, 0, 0],

You can't declare variable inside an array declaration. Instead do this:

connection.query(sql, function(err, result){
// Here you can declare series like this or however else you like
  const series = [result.length, 0, 0]
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.