1

I can't seem to figure out how the exact syntax to display data I have from a a database. I have 1 row in my user database which has a Password, Email, Username field but I can't seem to display it. I just get a blank screen

I've added the function and ejs file that I'm trying to fugure out. it displays perfectly in the console

//controller.js

module.exports = function(app){
app.get('/users', function(req,res){
    let sql = "Select * from users";
    let query = db.query(sql, (err,result) => {
        if(err){
            console.log(err);
        }
        console.log(result);
        res.render('users', {user: result});

    }); 
});

}

ejs file

<html>
  <head>
    <title>Users List</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script></script>
    <link href = "/assets/style.css" rel="stylesheet" type ="text/css" />
</head>
<body>
    <div id ="todo-table">
        <li><%= player.Email %></li>
    </div>
  </body>
</html>

1 Answer 1

1

The mysql driver returns results in an array, even if there is only a single row returned. So you might need to return result[0] to get the single row.

Sign up to request clarification or add additional context in comments.

1 Comment

God bless you. Correct!

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.