PHP Loading MySQL Columns For a UniqieID Then Updating Columns - php

Sorry very new to PHP and MySQL. I'm pretty close to having what I need. I created a database that hold values as shown here:
I was able to find some things online to create a form and initially get the data into the database
What I would like to do is have another page to load values for a specific customer by searching for their uniqueid. So have a input box where you input the uniqueid then the current values for that customer get loaded into a form just like the "Customer Creation Form". Then be able to update the loaded values in the the form and save it back. The enddate is probably the field that would be updated the most.

You could use Ajax requests and PHP to update the form live (or update once the user has entered the UniqueId)
https://www.w3schools.com/php/php_ajax_php.asp
To return multiple values grabbed from the database, use php to create an array return it as a json file.
https://www.w3schools.com/js/js_json_intro.asp
https://www.w3schools.com/js/js_json_arrays.asp
https://www.w3schools.com/js/js_json_php.asp

Related

Moodle Custom Form updating

I have created custom form in Moodle and inserted the data into moodle database. Also i used most of the field in form as autocomplete like below eg
$mform->addElement('autocomplete', 'SBName', get_string('searcharea', 'search'), $sbnames, $options);
Then, I need to update this form . I got record from db as a array, Then i need to add db values in my update form to proceed further.
Here I could not populate the values in edit form for the field of autocomplete $mform->addElement('autocomplete.
Kindly help on this to apply the values in edit form.
Please let me know Is there any way to do this in moodle
A few things to note - in Moodle variables and database field names should all be lowercase, so you will find things easier if you call the field 'sbname' instead of 'SBName'.
You mention you have "got the record from the db as an array" - none of the Moodle database access functions return a record as an array, they all return records as objects (although they will return multiple records as an array of objects) - please double-check the code you are using to retrieve the record, if it is reaching you as an array.
Finally, to initialise values when editing a form, the usual method is to write (outside the form itself):
$form = new name_of_form();
$form->setData($recordfromdatabase);
Where $recordfromdatabase is the record object returned by one of the $DB->get_record_* functions.
After that, you can use the $form->getData() function to retrieve the submitted values and $form->display() to display the form itself.
There are lots of examples in the core Moodle code that you can follow for this.

Update select contents without reloading form

I have quite a long form which has many HTML form selects pulling data from MySQL tables - quite often a client will be mid way through filling in the form when they realise that the value they want for department, for example, has not yet been entered into the system so is not in the list.
I have added a link to a simplified popup for adding departments but after it is added it does not appear in the select list as the contents of that select are based on what was available on the load of the page when the initial query ran - how can I get the select to update without having to submit and then edit, without the page refreshing/reloading and without the client losing the data they have currently added?
Thanks
Did read what you are asking, since its too long) But did you try javascript? changing form values after paged loaded is possible only with javascript.
When submit form on that popup, save it with ajax in database, and as response get inserted data... Then on ajax success add new option in select ( with returned data )

JQuery Dynamic Table

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...

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.

passing a dynamic html table to php as an array

I have a dynamic html table( rows are added dynamically using java script) and I want to pass whole table to a php script as an array.Is there a way to insert the table data to an array?
I have tried using phpTableExtractor but it dosen't extract dynamically added rows.
I don't see any other reliable solution but creating a HTML form along with the table and have the user click a submit button to save the table. Then you can read all content from $_POST and store it in a database.
Another solution would be to use AJAX requests to store the table content every time the focus changes or something like that. Will make your page dependent on JavaScript though.
What if you fill a JS array at the same time you create the table?
You will use the html just for display but behind you have the data you send to php.

Categories