Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Javascript help needed (returning the value from MySQL in a function) - Page 3
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Javascript help needed (returning the value from MySQL in a function)

13

Comments

  • @Hxxx said:
    If you are doing something that have to deal with front-end, hopefully you use JS and make the UX/UI work fluently instead of doing a refresh every time the customer does a click. I mean... well shit it is 2017. There is nothing more agonizing than using something that refreshes the whole page every time an action is being executed.

    React handles rendering really well.

    Thanked by 1Hxxx
  • KuJoeKuJoe Member, Host Rep

    @Hxxx said:
    If you are doing something that have to deal with front-end, hopefully you use JS and make the UX/UI work fluently instead of doing a refresh every time the customer does a click. I mean... well shit it is 2017. There is nothing more agonizing than using something that refreshes the whole page every time an action is being executed.

    Thankfully there is no UI, it interacts with an API directly with no web interface.

  • KuJoeKuJoe Member, Host Rep

    Farish said: Did you try the updated code?

    Not yet. I will give it a try shortly but I think I'll still be switching to Python to make my life easier. :)

  • @KuJoe said:

    Farish said: Did you try the updated code?

    Not yet. I will give it a try shortly but I think I'll still be switching to Python to make my life easier. :)

    Use ruby and syntax wise this will be much easier to manage.

  • KuJoeKuJoe Member, Host Rep

    @Farish said:

    @KuJoe said:

    Farish said: Did you try the updated code?

    Not yet. I will give it a try shortly but I think I'll still be switching to Python to make my life easier. :)

    Use ruby and syntax wise this will be much easier to manage.

    I think Python would be my best bet since there are many more projects down the road that I plan on doing and Python is really big in the Raspberry Pi community.

  • Intercal. The world is moving towards Intercal.

  • KuJoeKuJoe Member, Host Rep

    I feel so dumb. I was looking at this the wrong way. Turning the MySQL query into a function like a sane person was wrong, putting the MySQL query directly into the code worked 100% the way it's supposed to.

  • @WSS said:
    Intercal. The world is moving towards Intercal.

    PLEASE GIVE UP !

  • jetchiragjetchirag Member
    edited September 2017

    Here's how it'd work:

    https://gist.github.com/jetchirag/daae82cb617e0f1a1c83fd08c99418e3

    I'm also a mainly php developer and getting familiar with this approach was hard

  • CConnerCConner Member, Host Rep

    jetchirag said: Here's how it'd work:

    ``` var bufferString;

    function getQuote(callback) { bufferString = "I'm groot"; callback(); } function sendOut() { console.log(bufferString); } getQuote(sendOut);

    ```

    I'm also a mainly php developer and getting familiar with this approach was hard

    PHP has callbacks as well ;)

  • @CConner said:

    PHP has callbacks as well ;)

    You can use callbacks in most languages. What I meant is we don't always use them.

  • @KuJoe The key difference is generally php does things serially and waits for a response. Node.js can do multiple things at once and does not wait, thus a callback to trigger when ready.

    PHP can be made like node.js trough extensions.

  • PHP is bad, but it's rarely that bad. Just the coders who make it so. (I lie, PHP 7 is still highly crap.)

  • CConnerCConner Member, Host Rep
    edited September 2017

    WSS said: PHP is bad, but it's rarely that bad. Just the coders who make it so. (I lie, PHP 7 is still highly crap.)

    I guess you are one of those people that knows very little about PHP itself and just jumps on the "PHP SUCKS" bandwagon.

    There is a lot of bad PHP code out there because the amount of novice PHP programmers - however, that does not mean the langauge is bad. At least provide a reason for your bold statements next time.

    Thanked by 1Hxxx
  • BharatBBharatB Member, Patron Provider

    @Kujoe nodejs is better for scalability.

  • Like any other thing @WSS says, is all fake news. Remember he is a living meme.

    @CConner said:

    WSS said: PHP is bad, but it's rarely that bad. Just the coders who make it so. (I lie, PHP 7 is still highly crap.)

    I guess you are one of those people that knows very little about PHP itself and just jumps on the "PHP SUCKS" bandwagon.

    There is a lot of bad PHP code out there because the amount of novice PHP programmers - however, that does not mean the langauge is bad. At least provide a reason for your bold statements next time.

  • @KuJoe I work with JS on a daily. I'll shoot you a message, happy to help anyway I can.

  • raindog308raindog308 Administrator, Veteran

    CConner said: I guess you are one of those people that knows very little about PHP itself and just jumps on the "PHP SUCKS" bandwagon.

    I don't hate PHP and I know it.

    And really, PHP is an awful pile of garbage. Most seasoned PHP programmers have simply learned to work around its shortcomings. PHP is neither predictable nor consistent, and its libraries reflect the "throw crap at the wall" approach the language took to development. The inconsistent choices of naming funcitons in its libraries alone are amateurish.

    To put php on the same plane as perl or python is absurd. Even PHP people don't defend that.

    CConner said: At least provide a reason for your bold statements next time.

    I could say more, but the web is full of reasons why PHP sucks: https://www.bing.com/search?q=why+php+sucks&form=APMCS1&PC=APMC

    Personally, "PHP is a fractal of bad design" is one of my faves: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

    Thanked by 1qrwteyrutiyoup
  • PHP is, quite bluntly, a whole load of C libraries with hooks written with a QBasic-like interpreter without the strong typecasting.

  • HxxxHxxx Member
    edited September 2017

    PHP has been improving a lot. The 7.x versions are pretty good.
    Is not like C#, C++, Python, Go or Node are any better. Each language has its faults. One language doesn't fit all purposes.

    PHP framework: Laravel is super solid. The main problem with PHP as with any other language are the devs. Lazy coding, insecure code, etc.

    Some people even say PHP is bad because of the bad coded plugin wordpress have.

    In reality most of the people that complain about a language surely don't understand it or don't have enough experience to make such statements.

    Aka show me your CS Ph.d then your statements might get some credibility.

    Thanked by 1CConner
  • raindog308raindog308 Administrator, Veteran

    Hxxx said: Aka show me your CS Ph.d then your statements might get some credibility.

    Um, where did you get yours? If not, why do your statements have credibility but those who disagree with you require a PhD...?

    Hxxx said: Is not like C#, C++, Python, Go or Node are any better.

    That is not even remotely defensible.

    It's a nice try at a troll, though.

    Thanked by 1qrwteyrutiyoup
  • That's the point neither my or yours (LET collective) statements / opinions about how good or bad is a programming language are truly valid. If someone really have the credentials (achievements for example: Ph.d ) then that's a different story, otherwise is all noise. Let's just simply say each language has a role.

    @raindog308 said:

    Hxxx said: Aka show me your CS Ph.d then your statements might get some credibility.

    Um, where did you get yours? If not, why do your statements have credibility but those who disagree with you require a PhD...?

    Hxxx said: Is not like C#, C++, Python, Go or Node are any better.

    That is not even remotely defensible.

    It's a nice try at a troll, though.

  • KuJoeKuJoe Member, Host Rep

    I appreciate the discussion but PHP is not the topic here nor will anybody in the world convince me to stop coding in PHP for my normal projects.

    I figured out a fix for my JS code on my own so I think I will continue using Node.JS for this project. :)

    Thanked by 1Hxxx
  • Good PHP is good. Bad PHP is really bad.

    @OP, Node.JS is well worth using, goodluck with your future projects.

  • Please, for the sake of keeping your memory footprint low, preventing memory leaks and not killing your MySQL server with thousands of connections, create a controlled MySQL pool of connections once at the start of your code, then use that MySQL connection to query data:

    http://xor.meo.ws/lU5IqIgskyQtAwgTIv-nzCiGFU0e_jGE.txt (Can't write that code into the post because CrapFlare...)

  • Using promise async/await to avoid callback hell (async/await is available on Node 7.6+)
    https://www.npmjs.com/package/promise-mysql

    When a library said they support promise, you can call it by const results = await mySqlQuery();

  • PHP gets more of a bad rap because of Wordpress, or does Wordpress get a bad rap because of PHP we may never know.

  • @Farish said:
    PHP gets more of a bad rap because of Wordpress, or does Wordpress get a bad rap because of PHP we may never know.

    Both.

  • CConnerCConner Member, Host Rep
    edited September 2017

    WSS said: @Farish said: PHP gets more of a bad rap because of Wordpress, or does Wordpress get a bad rap because of PHP we may never know.

    Both.

    Oh just stop. Ever taken a look at how Wordpress is written? That right there is the definition of bad code. That does not make the programming language. Nor does you writing bad code in whatever other language make the language itself bad.

  • KuJoeKuJoe Member, Host Rep

    @Fusl said:
    Please, for the sake of keeping your memory footprint low, preventing memory leaks and not killing your MySQL server with thousands of connections, create a controlled MySQL pool of connections once at the start of your code, then use that MySQL connection to query data:

    http://xor.meo.ws/lU5IqIgskyQtAwgTIv-nzCiGFU0e_jGE.txt (Can't write that code into the post because CrapFlare...)

    I looked into this but connecting the MySQL server when I needed the data was significantly easier for me and works perfect for my needs. Thanks for the suggestion though.

Sign In or Register to comment.