I am building a voting system using codeigniter framework. There is a page in which I am showing a list of 10 people with there total vote and I wanted to make these voting count in realtime e.g voting count should change when user votes.
Now to make all the finalist total votes real time, I am using node.js but unfortunately the program is not getting the total count.
var express = require("express");
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'voting_sys',
});
var app = express();
connection.connect(function(err){
if(!err) {
console.log("Database is connected ... nn");
} else {
console.log("Error connecting database ... nn");
}
});
app.get("/",function(req,res){
connection.query("SELECT count('*') as votes from voting where finalist_id_fk=1", function(err, rows, fields) {
connection.end();
if (!err)
console.log('The solution is: ', rows);
else
console.log('Error while performing Query.');
});
});
app.listen(3000);
When I run this file it only show database is connection where as I want total votes
Please help me. How can I achieve it and how can I run this node.js file.