Jump to content

Editable table in php


Recommended Posts

Hi Friends,

I need to create a editable table and all the values in the table should be summited with a single save button, Please help. I was able to save the rows separately but actually what i need is to submit all the modified text in a single button instead a separate button beside each rows.

Link to comment
Share on other sites

Hi Requinix,

Thanks for ur reply!

here is my code!

   <table class="table table-hover font" id="user_table">
            <th>RESULT DESCRIPTION</th>

        $sql_fin_update = "SELECT
    || '/'
    ||A.Product_Code as Product,B.Description_Arb as Description,A.Remarks as Remarks,D.Result_Description as Result_Description,
C.Showroom_Code as showroom_Code,C.Invoice_No as Invoice_No,A.Entered_On as Entered_On,A.User_Id as User_Id
Inv_Qc_Schedule_Detail A ,Inv_Dsales C,Inv_Product B,Inv_Qc_Visitresult D
A.Showroom_Code       = '$SHOWROOM_CODE_Q'
And A.Invoice_No      = $invoice_q
And C.Showroom_Code   = A.Showroom_Code
And C.Invoice_No      = A.Invoice_No
And C.Serial_No       = A.Inv_Srlno
And B.Department_Code = C.Department_Code 
And B.Product_Code    = C.Product_Code
And D.Visit_Result    = A.Qc_Finding";

        $sql_fin_parse = oci_parse($conn, $sql_fin_update);

        while ($row_coun_fin = oci_fetch_array($sql_fin_parse, OCI_RETURN_NULLS + OCI_ASSOC)) {
            <tr id="row<?php echo $row_coun_fin['PRODUCT']; ?>">
                <td id="pro_val<?php echo $row_coun_fin['PRODUCT']; ?>"><?php echo $row_coun_fin['PRODUCT']; ?></td>
                <td id="desc_val<?php echo $row_coun_fin['PRODUCT']; ?>"><?php echo $row_coun_fin['DESCRIPTION']; ?></td>
                <td id="remarks_val<?php echo $row_coun_fin['PRODUCT']; ?>"><?php echo $row_coun_fin['REMARKS']; ?></td>
                <td id="result_val<?php echo $row_coun_fin['PRODUCT']; ?>"><?php echo $row_coun_fin['RESULT_DESCRIPTION']; ?></td>
                <td style="display: grid;">
                    <input type='button' class="edit_button btn btn-info btn-sm m-1" id="edit_button<?php echo $row_coun_fin['PRODUCT']; ?>" value="edit" onclick="edit_row('<?php echo $row_coun_fin['PRODUCT']; ?>');">
                    <input type='button' style="float: right;" class="save_button btn btn-success btn-sm m-1" id="save_button<?php echo $row_coun_fin['PRODUCT']; ?>" value="save" onclick="save_row('<?php echo $row_coun_fin['PRODUCT']; ?>')">
    function save_row(id) {
        var remarks_text = document.getElementById("remarks_text" + id).value;
        var remarks_text = document.getElementById("remarks_text" + id).value;
        var remarks_text = document.getElementById("remarks_text" + id).value;
        var result_text = document.getElementById("result_text" + id).value;
            type: 'post',
            url: 'modify_records.php',
            data: {
                edit_row: 'edit_row',
                row_id: id,
                remarks_val: remarks_val,
                result_val: result_val,
                showroom_code_q: showroom_code_q,
                invoice_q: invoice_q
                //  showroom_code_q: showroom_code_q,
                // invoice_q: invoice_q
            success: function(response) {
                if (response == "success") {
                    document.getElementById("remarks_val" + id).innerHTML = remarks_val;
                    document.getElementById("result_val" + id).innerHTML = result_val;
                    document.getElementById("edit_button" + id).style.display = "block";
                    document.getElementById("save_button" + id).style.display = "none";

Thank you. Please assist me

Link to comment
Share on other sites

I don't know where the textboxes are, but that might not matter.

The simplest method to make this work would be to save all the rows by using a loop to find all the rows and update each one individually. That's okay if you don't have many rows.
If you do have many rows then you'll have to make some more significant changes. The first one would be making modify_records.php able to update multiple records at once...

Link to comment
Share on other sites

I'll add to @requinix's response.

As he said, the easiest approach would be to have a save button that loops through all the rows in the table (except the header) and executes the save individually. Your current save operation only requires an id value. So, I would leave the current save_row() functiona unchanged and then do two things:

  1. In the script that builds the table, create a hidden field with the value being the ID
  2. Create a new function [e.g. save_all()]. Have that function iterate through every row in the table and get the ID value and execute the save_row() function

However, as he said if you have "lots" of rows, this may not be a good approach because each AJAX call would have to be performed separately. You would have to do some testing with the maximum number of records you expect to have to see if it will be an issue. If so, I would take a different approach.

I would make the values in the rows actual input fields - making the field names an array. Something like:

echo "<input type='text' name='records[{$row_coun_fin['PRODUCT']}][remarks_val]' value='{$row_coun_fin['REMARKS'];}'>";

Then you can submit the whole form via a normal POST or via AJAX. Then the receiving page would just need to iterate over the $_POST['records'] array

foreach($_POST['records'] as $productID => $productData)

	//Update the data for the current record from the values in $productData



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.