JQuery Dynamic Table - php

I have a form with a dynamic table on it plus other fields. You start with one row and can add more at execution time. It's used to track incoming and outgoing items on a store. You add each item and then fill some common fields (time, date, person who received them, etc).
General fields are stored in a table, detail ones in another table which is related with ID field of the first table. I send first the general fields with jquery ajax, save them on db and then use the ID for saving the details with other ajax call. When finished saving, I clean the inputs with jquery and if I add another registry the previous items are also added unless I reload the whole page. I use mysql+php+jquery 1.7.1
How do I clean the Array? or what is the best method for doing this?
Tell me if you need some code, thanks in advance...

Related

How to add multiple item using only one button?

I'm making a simple inventory system using PHP and MySQL.
Is it possible to add multiple items after clicking a button and save them into a database? Like adding 5 items with different stock no.
I can only add one item at a time.
You'll need to add additional input fields in your form for each item you want to add. Each one will need a unique name (e.g. item_0, item_2, etc...). In your form handler, it should check which ones are not empty, and insert them.
If you need help implementing, post the code that you currently have.

Multiple Listboxes to Select Data(table1) and Insert to MySQL Table2

I have two tables, incldues and TIncludes which are used for storing three columns of data; An ID, macro_num, macro
The includes(table1) has all of the items possible to list, these are shown by macro_num in a listbox on the form (select1). The user can add the wanted items to the second box, select2. The listboxes populate and move the data to eachother, add/remove buttons using javascript.
I can't seem to get the data from select2 to insert into my database. Not sure what I setup incorrectly or overlooked.
Are there any working examples of such a thing? I have only seen where one item is inserted and that is fine, but I have some reports which need 40 items.
Thanks in advance for reading this. I hope there may be a quick solution as I have not dealt with this problem before.. my first large form item requirement.
The PHP form handler is only going to know about the options that are selected in your list. You'll need to do more than just add the items to a select element to get them to your code. You can add them to hidden elements, or you might be able to force a select-all through javascript as the form is submitted.

what is the best way to make a pre-canned response feature

what is the best way to make a pre-canned response feature within a form that submits a query on selection of a drop down list.
(the drop down list is currently populated via php sql foreach loop).
I wish to use the id of the item selected in the drop down, which is stored in the value, to report back to the sql to retrieve the same row of data only a different column....the message also that dynamically populates a text area without having php post from and back to the same page.
If I'm understanding you correctly, why not json encode the data you use to populate the select list, and then take that extra step/lookup out of the process.
Then the onchange for the select list can simply grab the right item from the object and display the message in the text area, as well as set the id in a hidden field if you need that as well.
This way, you've taken the extra call to the server out of the process, and removed at least one additional sql query as well.

Multiple edit of a database table in one form

ok heres my problem.
I have a database table that i want to edit multiple rows by using one form.
I am looking for a way to be able to display a form in which i will be able to edit the rows and save the entries in a grid view kind of way.
Can this be done by dynamically letting the user choose which fields he wants to edit or provide an excel sheet kind of interface where changes are made and saved to this already existing database table.
Using PHP, if you name the form fields as nameoffield[] they will arrive in the request back to the server as an array. Just make sure empty fields have some place holder when they get sent back to the server and just parse through them one by one performing updates/inserts as necessary.

PHP / jQuery / AJAX form update best practices

On one of my pages I pull a table of data from the database and display it to the user, giving them the option to update the values for each row. My question is what is the best way to do this?
Currently, i'm stuck between two options. Option one is to display one form with all of the inputs. My other idea was to have each row be a form itself. Is there an advantage to one over the other? Right now i'm leaning towards the the latter of the two - as it seems like much less overhead to only POST data for one row as opposed to all of them for a single update.
You should certainly define separate forms for every row. No need to send all the data all the time.
Semantically, they are also separate forms. It is also easier to handle the data you get on the server side.
you could set it up so that when a record is clicked the data for that record(id,name,other...) are loaded into a form in a jQuery ui dialog then have two buttons on the dialog (save,cancel)
Save: use ajax to send the data to a php data helper which will update the record in the database
cancel: clear the fields in the form and close the dialog

Categories