Order of commands

Can anybody tell me if there is an order to command strings.

I have a site with a server connect database query that auto loads with the page
I have a second server connect database action that inserts to the same table in that database.
Lets say I had a button not inside a form that executed the insert action, and then queried the table to show the result of the insert.
I would normally do an onclick that fires the insert, and a onsuccess of the insert to refresh the query action.
Could i rather do an onclick to fire the insert first and then in the same onclick tell it to execute the query, I tried it and it worked, well in about 20 of the 25 tests, so 4 out of 5 times it works, then i reverted to the normal way with a single onclick insert, and a single onsuccess query, and did another 25 tests, all 25 worked.

So my question is, why, does the onclick execute both commands at the same time, and sometimes the insert is still executing and the data has already finished the query?

Hi Paul the only right order is:

  1. Run insert on click
  2. Insert onsuccess run the query

You should not run them both on click as they don’t know which has finished when :slight_smile:

1 Like

Thanks for clarifying, its what i thought, but figured i best check to be sure. :slight_smile:

It’s always better to wait for the response of the action you are executing and then run the other action.

Ok one more slightly silly question, what about server side, lets say i wanted to insert to 5 different tables from the same database, is it better to create a single server action that has 5 inserts, and will 1 insert finish and then do the next and then the third etc.

Or is it ok to make 5 insert server actions, and use a single onclick, with onclick run insert1;insert2;insert3;insert4;insert5
Obviously only meaning when the 5 inserts are not at all reliant on any data from the other inserts. These are 5 totally different inserts.

Oh and this is really just a theoretical question, for future usage.

You can just have a single action with 5 insert steps :slight_smile: they run after each other.

1 Like

Good to know thanks again.

1 Like