Thursday 24 January 2019

How do I dynamically push items in a res.render to a jade file

I need to be able to change the amount of students I access when doing res.render. Otherwise the program crashes. Sometimes I want to get three students, sometimes five, ect. How do I create a loop of variables to render and pass to my jade file? Any help is much appreciated.For Example one time I want to grab one student:router.get('/', function(req, res){var studentlist = "SELECT * FROM student, advises WHERE student.PID = advises.PID AND advisorid = '1'";getConnection().query(studentlist, (err, c) => {if (err) throw err;console.log(c);res.render('houme', {student_PID1: c[0].PID,student_fname1: c[0].fname,student_lname1: c[0].lname});});});Another time I want to grab two:router.get('/', function(req, res){var studentlist = "SELECT * FROM student, advises WHERE student.PID = advises.PID AND advisorid = '1'";getConnection().query(studentlist, (err, c) => {if (err) throw err;console.log(c);res.render('houme', {student_PID1: c[0].PID,student_fname1: c[0].fname,student_lname1: c[0].lname,student_PID2: c[1].PID,student_fname2: c[1].fname,student_lname2: c[1].lname});});});​

Submitted January 25, 2019 at 03:57AM by kevinisathought

No comments:

Post a Comment