Jump to content

roboBen

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by roboBen

  1. Thanks for responding!
    Wouldn’t you have to create the function to stop the original function until it’s finished? Similar to for-loop or multiple functions of fs?

    Could you explain to me again what these functions are for? If I go through this with sample numbers, it doesn’t make sense. But I’m the one who asks for help in the forum...

    On 10/9/2021 at 8:39 PM, Ingolme said:
    /* Function declarations */
    function handleResults() {
      // Leave the function if there are queries that haven't been completed yet
      if(numQueries > 0) {
        numQueries--;
        return;
      }
      
      // Access query results
      if(globalResults.resultsA) {
        // Do something with the results of the first query
      }
      
      if(globalResults.resultsB) {
        // Do something with the results of the second query
      }
    }

    Thank you for your efforts and your time and I hope to get another answer from you.

  2. Hey guys,

    I need your help with a problem I’ve been able to walk around so far.
    Namely, I want to make a mysql query in a node.js web socket:

     connection.query("SELECT * FROM DB WHERE id= ?;", [id], function(error, results, fields) {
                if (error) throw error;
             	// Code here...
            })

    In the variable results I can now use the data in the form of a JSON object. That’s not a problem.
    So far, I have done this so that when I wanted to make several queries, I have nested into each other. Like this:

     connection.query("SELECT * FROM DB WHERE id= ?;", [id], function(error, results, fields) {
                if (error) throw error;
             	 connection.query("SELECT * FROM DB WHERE id= ?;", [id], function(error, results, fields) {
                if (error) throw error;
             	// Code here...
            })
            })

    But now I need that some queries are only carried out if certain conditions are met. As a result, the queries can no longer be logically nested.
    That’s why I need something like this:

    if(a == b) {
    	 connection.query("SELECT * FROM DB WHERE id= ?;", [id], function(error, results1, fields) {
                if (error) throw error;
             	// Code here...
            })
    }
    
    if(c == b) {
    	 connection.query("SELECT * FROM DB WHERE id= ?;", [id], function(error, results2, fields) {
                if (error) throw error;
             	// Code here...
            })
    }
    

    And after both if loops I can logically no longer access the values results1 and results2.
    How can I do that? Do you need more information.

    I hope for some answers.

     

    Yours, Ben

×
×
  • Create New...