OK, so take a look at your template. Why are you iterating through the
'applications' variable?
After Muhammad's (good) advice you have changed the one variable called
'applications' (it was being overwritten, because you wrote it twice) with
two variables called 'grade7' and 'grade8'.
All of that would be fine, but in your template you don't display anything
if there's no 'applications' variable.
*router.get('/dashboard', getGrade7Applicants, getGrade8Applicants,
function (req, res, next) {*
* res.render('admission/dashboard', {*
* 'grade7': req._applications7,*
* 'grade8': req._applications8,*
* });*
*});*
The object marked in red is the one available to the context of the page,
as you can see there's no 'applications' to iterate. So, on to solutions.
You could remove the 'if' and 'each' portions of your template, so that you
simply print the contents of your object into the template, but that
requires a fairly static template. Or you could put the variables you want
to display within an 'applications' object, like this:
*router.get('/dashboard', getGrade7Applicants, getGrade8Applicants,
function (req, res, next) {*
* res.render('admission/dashboard', {*
* applications: {*
*'grade7': req._applications7,*
* 'grade8': req._applications8,*
* }*
* });*
*});*
For your next bit, consider moving the labels to the object:
*router.get('/dashboard', getGrade7Applicants, getGrade8Applicants,
function (req, res, next) {*
* res.render('admission/dashboard', {*
* grades: [{*
*'label': '*7th GRADE Applications'*,*
* 'count': **req._applications7*
* }, {*
*'label': '*8th GRADE Applications'*,*
* 'count': **req._applications8*
* }]*
* });*
*});*
*and then iterate through the objects and display them as required.*
On Thursday, 26 January 2017 05:16:03 UTC, Fatih Karatay wrote:
>
> When I do this, nothing is displayed. That drives me crazy. Here is my
> html teample completely:
>
> <div class="container">
> <div class="row">
> <h2>Number of Applications</h2>
> {{#if applications}}
> {{#each applications}}
> <div class="col-lg-2">
> <div class="alert alert-success" role="alert">
> <p style="font-size:75px;
> text-align:center;">{{grade7}}</p>
> <p style="text-align:center;"><strong>7th GRADE
> Applications <strong> </p>
> </div>
> </div>
> <div class="col-lg-2">
> <div class="alert alert-warning" role="alert">
> <p style="font-size:75px;
> text-align:center;">{{grade8}}</p>
> <p style="text-align:center;"><strong>8th GRADE
> Applications <strong> </p>
> </div>
> </div>
> {{/each}}
> {{else}}
> <p>No Applications</p>
> {{/if}}
> </div>
> </div>
> </div>
>
> On Wednesday, January 25, 2017 at 1:18:50 PM UTC-6, Muhammad Wasim wrote:
>>
>> Set it as following
>>
>> *router.get('/dashboard', getGrade7Applicants, getGrade8Applicants,
>> function (req, res, next) {*
>> * res.render('admission/dashboard', {*
>> * 'grade7': req._applications7,*
>> * 'grade8': req._applications8,*
>>
>> * });*
>> *});*
>>
>> *And here is my html template. I use handlebars. *
>>
>> <div class="alert alert-success" role="alert">
>> <p style="font-size:75px; text-align:center;">{{grade7}}</p>
>> <p style="text-align:center;"><strong>7th GRADE Applications
>> <strong> </p>
>> </div>
>>
>> <div class="alert alert-success" role="alert">
>> <p style="font-size:75px; text-align:center;">{{grade8}}</p>
>> <p style="text-align:center;"><strong>8th GRADE Applications
>> <strong> </p>
>> </div>
>>
>> Muhammad Wasim.
>>
>> On 25 Jan 2017 12:26 a.m., "Fatih Karatay" <[email protected]> wrote:
>>
>> *Here is the router js file that I use :*
>>
>>
>> *//connection variables*
>> *var connection = mysql.createConnection({*
>> * host: 'localhost',*
>> * port: '3306',*
>> * user: 'root',*
>> * password: '12345*',*
>> * dateStrings: true,*
>> * database: 'database'*
>>
>> *});*
>>
>> *connection.connect();*
>>
>>
>> *function getGrade7Applicants(req, res, next) {*
>> * connection.query('SELECT COUNT(*) AS grade7 FROM applications WHERE
>> grade="Grade 7" ', function (err, rows, fields) {*
>> * if (err) {*
>> * return next(err);*
>> * };*
>> * req._applications7 = rows;*
>> * return next();*
>> * });*
>> *}*
>>
>> *function getGrade8Applicants(req, res, next) {*
>> * connection.query('SELECT COUNT(*) AS grade8 FROM applications WHERE
>> grade="Grade 8" ', function (err, rows, fields) {*
>> * if (err) {*
>> * return next(err);*
>> * };*
>> * req._applications8 = rows;*
>> * return next();*
>> * });*
>> *}*
>>
>>
>>
>> */* GET dashboard page */*
>>
>> *router.get('/dashboard', getGrade7Applicants, getGrade8Applicants,
>> function (req, res, next) {*
>> * res.render('admission/dashboard', {*
>> * 'applications': req._applications7,*
>> * 'applications': req._applications8,*
>>
>> * });*
>> *});*
>>
>> *And here is my html template. I use handlebars. *
>>
>> <div class="alert alert-success" role="alert">
>> <p style="font-size:75px; text-align:center;">{{grade7}}</p>
>> <p style="text-align:center;"><strong>7th GRADE Applications
>> <strong> </p>
>> </div>
>>
>> <div class="alert alert-success" role="alert">
>> <p style="font-size:75px; text-align:center;">{{grade8}}</p>
>> <p style="text-align:center;"><strong>8th GRADE Applications
>> <strong> </p>
>> </div>
>>
>> *I know there is override in here. What would be best way to display
>> those count values from the same table in the same page?*
>>
>> On Wed, Jan 11, 2017 at 4:41 AM, Alex Wells <[email protected]> wrote:
>>
>>> 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
>>>
>>> <https://groups.google.com/d/msgid/nodejs/75ac96b4-05d4-4948-b2ec-699a86001c8b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Fatih Karatay
>> Dove Science Academy Tulsa
>>
>> --
>> 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/CAASE%3DRhT-UF8Ty63BOo-TLgZj-E9R7MfKguBPYsPxLoCjunH%2BQ%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/nodejs/CAASE%3DRhT-UF8Ty63BOo-TLgZj-E9R7MfKguBPYsPxLoCjunH%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
--
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/bff9a794-c5db-41eb-a861-91393566942e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.