Table is not updated

Table is not updated

Hildeb67Hildeb67 Posts: 72Questions: 19Answers: 1

Hello,
I have a table that is invisible in the background.
Only the form is displayed. There are two tabs in this form
In the first tab there is a drop-down menu (see red frame).
If I now make a selection in the drop-down menu, it should appear in the second tab
a table to be filled with data.
This also works, but the next time you change the dropdown menu will be
Unfortunately, the data in the table is no longer updated.
What could be the reason?

Here is the link

https://feuerwehr.diedorf.bayern/FOM/uebung_neuju.php

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,374Questions: 26Answers: 4,957

    I receive this message prompting to login:

    Please log in first

    You can PM Allan the login info if you don't want to post it here.

    Kevin

  • Hildeb67Hildeb67 Posts: 72Questions: 19Answers: 1

    you have to click on "Create exercise"

  • kthorngrenkthorngren Posts: 21,374Questions: 26Answers: 4,957

    The first page I get is this:

    When I click the link I presented with this page:

    I don't have the option to "Create exercise".

    Kevin

  • Hildeb67Hildeb67 Posts: 72Questions: 19Answers: 1

    Hi Kevin. I have postet the login details to you

  • kthorngrenkthorngren Posts: 21,374Questions: 26Answers: 4,957
    Answer ✓

    I took a look and not clear on what you are doing. Selecting an option in the first tab then clicking on the seconds sends two Ajax requests to the server. The first request either inserts some data in to the DB or it deletes data from the DB. The second request then fetches the table data. For example:

    Select candidate for Youth group and I see this payload:

    uebungsid: 11
    feuerwehrIDphp: 3
    grstatusphp: Anwärter
    

    Then this result:

    ["INSERT INTO ffwuebungsteilnehmermarktdiedorfju (FWID,UEBUNGSID,KRAFTID,KRAFTJA,KRAFTNAME,TEILGENOMMEN,UNTERATEMSCHUTZ,ZEIT) VALUES ('3','11','375','0','Wiesnermann Michaella','0','0','0')"]
    

    It is inserting some data with FWID set to 3 and UEBUNGSID set to 11.

    Then the second request is sent with this response:

    {"data":[],"options":[],"files":[],"debug":
    [{"query":"SELECT  `id` as 'id', `ID` as 'ID', `FWID` as 'FWID', `UEBUNGSID` as 'UEBUNGSID', `KRAFTID` as 'KRAFTID', `KRAFTJA` as 'KRAFTJA', `KRAFTNAME` as 'KRAFTNAME', `TEILGENOMMEN` as 'TEILGENOMMEN', `ZEIT` as 'ZEIT', `JAHR` as 'JAHR' FROM  `ffwuebungsteilnehmermarktdiedorfju` WHERE `FWID` = :where_0 AND  `UEBUNGSID` = :where_1 ",
    "bindings":[{"name":":where_0","value":"3","type":null},{"name":":where_1","value":"11","type":null}]}]}
    

    Searching for the same values of FWID = 3 and UEBUNGSID = 1.

    Changing to Candidates and youth Is see this payload:

    uebungsid: 11
    feuerwehrIDphp: 3
    grstatusphp: Anwärter+Jugend
    

    Followed by this response:

    ["DELETE FROM ffwuebungsteilnehmermarktdiedorfju WHERE UEBUNGSID = 11 AND KRAFTJA = 0 AND FWID = 3"]
    

    Deleting all records. Then the ajax response for Datatables contains this response:

    {"data":[],"options":[],"files":[],"debug":[{"query":"SELECT  `id` as 'id', `ID` as 'ID', `FWID` as 'FWID', `UEBUNGSID` as 'UEBUNGSID', `KRAFTID` as 'KRAFTID', `KRAFTJA` as 'KRAFTJA', `KRAFTNAME` as 'KRAFTNAME', `TEILGENOMMEN` as 'TEILGENOMMEN', `ZEIT` as 'ZEIT', `JAHR` as 'JAHR' FROM  `ffwuebungsteilnehmermarktdiedorfju` WHERE `FWID` = :where_0 AND  `UEBUNGSID` = :where_1 ","bindings":[{"name":":where_0","value":"3","type":null},{"name":":where_1","value":"11","type":null}]}]}
    

    With no rows. I'm not sure what the goal is here. Maybe it doesn't matter for the issue you are seeing.

    I noticed, as you mentioned above, that there is inconsistency in the responses. Looks like the function alleueteileintragen(() is used for the first Ajax request followed immediately by initializing Datatables. I believe the problem you are running into is the asynchronous nature of ajax and not waiting until the first request is complete before initializing Datatables and fetching the row data. You will want to use the success function of the ajax request in alleueteileintragen(() to init Datatables so that it waits until the inserting or deletion of records takes place.

    Kevin

  • Hildeb67Hildeb67 Posts: 72Questions: 19Answers: 1

    Thank you very much for your help. I added the function for calling the table after the success message from Ajax.

        function alleueteileintragen(grstatus,ueid) {
        
            $.ajax({             
                        url: "./controllers/alle_ueteilnehmer_eintragenju.php",
                        type: 'post',            
                        data: {uebungsid:js_variable_ueid, feuerwehrIDphp:js_variable_feuerwehrid, grstatusphp:grstatus}, // {Feld in php Datei:Datenfeld das gesendet werden soll}           
                        success: function (data) {
                            const myArr = JSON.parse(data); 
                uebungsteilnehmerfüllen(ueid);                      
                            return data;                       
                        },              
                        error: function(data){ 
                        }
                    })
        }
    
Sign In or Register to comment.