You're probably not decoding the JSON in the client and then choosing the
right variables. I haven't got your Template so I can't help you fix that,
but you'll need to reference the 'data.grade6Rows' and 'data.grade7Rows'
objects you created, rather than the '_applications.grade6Rows' you were
referencing previously.
On Wednesday, 11 January 2017 01:54:28 UTC, Fatih Karatay wrote:
>
> When I try your solution, this time nothing is displayed. Am I missing
> anything?
>
> On Tuesday, January 10, 2017 at 7:35:49 AM UTC-6, Alex Wells wrote:
>>
>> Just so you know, it's a bit weird to set a 'private' property on an
>> object you don't own:
>>
>> req._applications = rows;
>>
>>
>> although this is just by convention, if you were to log a bug with
>> something I had developed where you'd made use of the above, I would
>> probably ask you to change this first. If you want to set something on the
>> req object, most people set a 'data' variable like so:
>>
>> req.data = {
>>
>> grade6Rows: rows;
>>
>> };
>>
>>
>> In the above is also the solution - you are setting the same property both
>> times ('_applications') so it's getting overwritten by subsequent
>> callbacks. You need to place multiple properties in the 'req' object for
>> each resultset.
>>
>> You would do that in each callback with something like this;
>>
>> req.data = req.data || {};
>>
>> req.data['grade6Rows'] = rows;
>>
>>
>> Remember to decode the JSON on the client, and you'll have an object you
>> can iterate.
>>
>> On Thursday, 5 January 2017 21:04:06 UTC, Fatih Karatay wrote:
>>>
>>> I have a web page that displays number of applications in certain
>>> grades. For example, number of applications in grade 6, grade 7 and grade
>>> 8. The functions that I use for grade 6 and grade 7 are as below:
>>>
>>> function getGrade6Applicants(req, res, next) {
>>> connection.query('SELECT COUNT(*) AS grade_6 FROM applications WHERE
>>> grade="Grade 6" ', function (err, rows, fields) {
>>> if (err) {
>>> return next(err);
>>> };
>>> req._applications = rows;
>>> return next();});}
>>> function getGrade7Applicants(req, res, next) {
>>> connection.query('SELECT COUNT(*) AS grade_7 FROM applications WHERE
>>> grade="Grade 7" ', function (err, rows, fields) {
>>> if (err) {
>>> return next(err);
>>> };
>>> req._applications = rows;
>>> return next();});}
>>>
>>> Then, I use this function to my GET request as below. If it's just for
>>> grade_6, it works fine. The name of the mysql table is "applications".
>>>
>>> /* GET dashboard page */
>>> router.get('/dashboard', getGrade6Applicants, function (req, res, next) {
>>> res.render('admission/dashboard', {
>>> 'applications': req._applications
>>> });})
>>>
>>>
>>> This gives me the number of applications in grade6 in my applications
>>> table in mysql database.
>>>
>>> I use this in my dashboard.handlebars page as {{grade_6}} using
>>> appropriate {{#if}} and {{#each}} built in helpers.
>>>
>>> The problem is whenever I wanted to add *second *function to display
>>> number of applications in grade 7, what I have is only grade 7
>>> applications. Grade 6 is not shown. Here is the GET request that I use for
>>> multiple values:
>>>
>>>
>>> /* GET dashboard page */
>>> router.get('/dashboard', getGrade6Applicants, getGrade7Applicants, function
>>> (req, res, next) {
>>> res.render('admission/dashboard', {
>>> 'applications': req._applications
>>> });})
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/75ac96b4-05d4-4948-b2ec-699a86001c8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.