facebook

Calling function in loop

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #325470 Reply

    Max87
    Member

    Hi guys,
    I have a problem with my app.
    I read a multi dimensional array(6×3 entries). In 2 loops, I use FOR to get the values from this field. I’d like to call function every time, when loop is repeating(insert row into table), but it calls only once and with last data.
    Can you please help me, how to call function every time?
    Code attached.
    Thx for any help.

    edit: calling console.log is working perfectly. Problem is with db.transaction and inserting rows into table.

    Attachments:
    You must be logged in to view attached files.
    #325476

    ramonck
    Member

    Hey Max,

    Try changing

    number[j]connections[i][j] -> connections[i][j]

    you should get the multi dimensional value.

    concat the info like this:

    
    var valString;
    
    for(i=0;i<3;i++)
        {
          for(j=0;j<6;j++)
          {
           if(valString){
              valString += ' ,'+connections[i][j];
           } else {
              valString = connections[i][j];
           }
          }
    db.transaction(function (tx) 
            {  
            tx.executeSql('INSERT INTO spoje(id_spoja, id_spojenia, tarifa, id_zastavky, km, cas_odjazdu) VALUES (?,?,?,?,?,?)',[valString]);
          });
         
          
       }
    }
    
    #325478

    Max87
    Member

    Hello ramonck,
    thx for help, but when I apply your code, it’s not working properly.
    I don’t understand

    Try changing

    number[j]connections[i][j] -> connections[i][j]

    In my txt file is mismatch – ‘=’ is missing, the right sentence should be

    number[j]=connections[i][j] -> connections[i][j]

    Another bad thing is, that row inserting is not working(dtb is empty) and when I add

    console.log(valString)

    after db.transaction, it logs like this:

    1 ,4 ,2 ,112 ,0 ,455
    1 ,4 ,2 ,112 ,0 ,455 ,1 ,4 ,3 ,41 ,1 ,458
    1 ,4 ,2 ,112 ,0 ,455 ,1 ,4 ,3 ,41 ,1 ,458 ,1 ,4 ,4 ,23 ,2 ,500

    Thx for any help

    #325489

    Max87
    Member

    Hi guys,
    I updated my code with onError function and it states, that there is a problem with number of ‘?’.
    I think, thats because I have 6 times ‘?’ and one variable valString to insert.

    #325492

    Max87
    Member

    Hi guys,
    I’ve manage to find a solution and it works!!!
    The thing is that FOR loop has to be IN db.transaction() not vice versa.
    I’ll post my code soon, if you want to.
    Thanks for helping me to solve this out.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Calling function in loop

You must be logged in to post in the forum log in