Sign in to follow this  
Hera

Javascript Scope Problem

Recommended Posts

    function MysqlName(sqlid, cb)
    {
        iHandle.mysql.handle.query("SELECT `Username` FROM `accounts` WHERE `UserID`= ?", [sqlid], function (err, rows, fields) {
            if (err) throw err;

               cb(rows[0].Username);
        });
    }

    var qwf = null;
        MysqlName(19, function (name) {
            qwf = name; 
            console.log("returning name: " + name) // return Firstname_Lastname (its ture)
        }
    );

    console.log(qwf); // RESULT NULL 

 

I did a function to pull the user name from the database. I can't assign it to global value. A very interesting mistake. How can I solve this?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.