On Nov 18, 2014 2:51 AM, Vasa <vijayaraj...@gmail.com> wrote:
>
> Hello noders
>
> i am trying to generate a chart (using highcharts) with queried data from Mysql.
[Snip]
> This is not working because the chart is drawn before the sql data is retrieved.
This is common as people start getting going in node. Move the drawing parts into the callback for the SQL query, so it waits until the data arrives.
Unlike php, request handlers don't just run to the bottom and stop. Instead, the top level is run which sets things up, which load data, which set things up and finally respond. Http responses aren't done until red.end(). That can be delayed as much as you need.
Next, you'll start nesting deeply, so http://callbackhell.com will be a short, good read for you.
Good luck!
Aria
Every time you have a function that you want to run first, that makes use of callbacks, such as:
myFunc(function(err, result) { ... });
Then you need to place the code you want to run second where ... is. This is the asynchronous nature of node. Any code where ... is will not run until myFunc is finished internally and calls it's argument function. If there's another synchronous function, meaning it doesn't accept a function as a parameter, outside of myFunc it will be run first. Otherwise they will be driven in order of the events caused by the user.
dbclient.query() needs to be inside of the anonymous (read: unnamed) function that's passed to dbclient.connect()
--
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 nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/cc403d67-c255-4edd-9a32-0fc6868f23af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you for pointing out the bug. I am new to PHP :). I fixed it and my PHP is working fine retrieving the data and charting. But i am trying to move the db queries to my nodejs. So that when a request is made, it queries the db and then tries to chart the data. I have attached my node server. Please help me out.