Local table editing & calling a sql stored proc to save

Local table editing & calling a sql stored proc to save

crcucbcrcucb Posts: 20Questions: 6Answers: 0

I would like to make the editing process so that when they click edit, a forn pops up that will have multiple check boxes or drop downs, a multi select, and comments. when it's saved, it won't actually use the php to update the source bu call a mssql stored proc passing all the values from the form to save back to the db. there maybe multiple updates based on what exactly the user selected in the form. I'm pretty good with sql but been learning datatools. From what I read, using local table editing is possibly what I need to create a space with all of the fields of information used to present to the user for edits. How do I collect the data, construct a string to call a stored proc?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,688Questions: 1Answers: 10,697 Site admin

    Hi,

    You don't need to use the provided server-side libraries for Editor, you can have your own, and that is what I would suggest in this sort of case. The data sent to the server for the Ajax request is fully documented and I'm happy to answer any questions you might have about it. It also shows the data that Editor expects back. What the server does with the data sent and how it gets the data to send back is a black box as far as Editor is concerned. It could go through a quantum computer on the surface of a black hole, with multiple AGIs managing it for all the Javascript cares :).

    The idea of that was for exactly this sort of case when you have your own data handling on the server-side that you want to use. The Editor PHP (.NET and Node.js) libraries aren't designed to cover all use cases - the 80/20 rule applies!

    Allan

  • crcucbcrcucb Posts: 20Questions: 6Answers: 0

    Thank you, I am on a time crunch and did not want to spend time going down the wrong road. Is there any concern if I let the edit post back to the PHP and inspect the action for Edit, then perform the updates there? I had a previous question about reviewing the $_POST and the depth of the arrays, and you suggested using the editor libraries. Am I able to use the editor libraries to get all of the data elements then call the stored procs?

  • allanallan Posts: 64,688Questions: 1Answers: 10,697 Site admin
    Answer ✓

    Is there any concern if I let the edit post back to the PHP and inspect the action for Edit, then perform the updates there?

    No.

    I had a previous question about reviewing the $_POST and the depth of the arrays, and you suggested using the editor libraries.

    Lol - sorry, I hadn't connected the two threads together in my head.

    Am I able to use the editor libraries to get all of the data elements then call the stored procs?

    No - not in the PHP ones (there is a model for it in the .NET libraries, but not PHP).

    Okay, so joining the dots now, if you want to use a stored proc. you don't have the option of using the provided libraries for Editor at the moment (one day I'll add support for it, but that isn't in yet).

    So you'll need to parse the data that is submitted. It isn't particularly complex data - the action is trivial, and the data property is nested with the row ids (to allow multirow editing) and the field values - so:

    foreach( $_POST['data'] as $pkey => $fields) {
      exec_my_stored_proc($pkey, $fields['myField1'], $fields['myField2'], ...);
    }
    

    You need to know the field names with the above, but presumably you do. You could create an abstraction layer if you want, but if you need to get a crack on, this would be the way to do it.

    You need to make sure that the JSON data you return in response to the edit (for the row being edited) is in the same format as the data you used to load the table initially. Normally you've just run it through the same SELECT function but with a WHERE condition applied for the rows in question.

    What you might find useful with this sort of thing, is to look at the Ajax data tab in an example like this one so you can see what data is being submitted to the server and what is being returned - so you know what your script needs to handle and what to return for the same actions.

    Allan

  • crcucbcrcucb Posts: 20Questions: 6Answers: 0

    Thank you, you are always very helpful

Sign In or Register to comment.