lecture_student.js
813 Bytes
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var conf = require('../conf/db');
var pool = mysql.createPool(conf.local)
/* GET home page. */
router.get('/:lecture_id', function(req, res, next) {
var lecture_id = req.params.lecture_id;
pool.getConnection(function(err, conn){
conn.query('select s.student_id AS student_id, s.student_name AS student_name from lecture_students l JOIN student s USING (student_id) where l.lecture_id=?;', [lecture_id], function (err, rows){
if (err) return res.status(500).json({error: err});
if (!rows) return res.status(400).json({error: 'not found'});
var msg = {
status: 'success',
err: '',
result: rows,
length: rows.length
};
res.json(msg);
});
conn.release();
});
});
module.exports = router;