Home>

I am trying to get the data in the table with the select statement after setting the condition with the if statement, but since it is the same select statement, I would like to reduce the weight collectively with the function.
The code provided is a part, and there are about 50,000 lines in total.
* We have also confirmed that there are about 1000 command statements in total.
This may be a rudimentary question, but please tell us.

Is it possible to display the result by grouping the same select statement with function?
Corresponding source code
if (aa == 0) {
   if (bb == 0) {
      if (cc == 0) {
        console.log ('all0');
      } else {
         var connection = mysql.createConnection (mysql_setting);
         connection.connect ();
         connection.query ('select * from db1',
         function (error, results, failds) {
            var kekka001 = results [0] .karamu1
      }
   } else {
         var connection = mysql.createConnection (mysql_setting);
         connection.connect ();
         connection.query ('select * from db1',
         function (error, results, failds) {
              var kekka001 = results [0] .karamu1
} else {
    var connection = mysql.createConnection (mysql_setting);
    connection.connect ();
    connection.query ('select * from db1',
    function (error, results, failds) {
         var kekka001 = results [0] .karamu1

After summarizing with function

function select () {
connection.query ('select * from db1',
function (error, results, failds) {
      var kekka001 = results [0] .karamu1
       connection.end ();
       res.redirect ('/ homepage');
});
}
if (aa == 0) {
   if (bb == 0) {
      if (cc == 0) {
        console.log ('all0');
      } else {
        select ();
      }
   } else {
         select ();
} else {
    select ();
What I tried

insert, update, delete are successful.

Supplementary information (FW/tool version, etc.)

It is created using node.js and Visual Studio Code.

  • Answer # 1

    Isn't it possible to ask if it's possible by trying it if you've written that much code?

    What is the meaning of an if statement that does everything else the same?
    (Is it just hiding other parts for stackoverflow?)
    If this code is followed, execute "console.log ('all0');" when aa = 0, bb = 0 and cc = 0, and access the DB in other cases, with one if I feel like I'm done.