PHP Ajax CRUD Application Tutorial – MySQL & Bootstrap & jQuery DataTables [Part 3]




PHP Ajax CRUD Application Finally Made Easy! Download Source Code: http://codingpassiveincome.com/php-ajax-crud-application-part-3 In this tutorial you …

Original source


26 responses to “PHP Ajax CRUD Application Tutorial – MySQL & Bootstrap & jQuery DataTables [Part 3]”

  1. How can I add custom drop-down search filters to this!? All my attempts ended in making the table go blank when I use the examples on the official page of the plugin!

    EDIT: I figured it out! If you create a Drop Down menu in html then just add this line: $('#dropDown').on( 'change', function () { $('.table').DataTable().column(1).search( this.value ).draw(); }); after $('.table').DataTable();

    Keep in mind this only works as a filter for one specific row! For multiple rows, you can consider adding the default API codes: https://datatables.net/examples/api/

    Now I have 2 more important issues. The table does not update after I add a new entry and if I edit an existing country and rename it to one that already exists it allows me to have duplicates which I would certainly like to avoid! Any help would be greatly welcomed! <3

    EDIT 2: For the edit duplicates I solved it like this in Ajax,php:

    if ($_POST['key'] == 'updateRow') {
    $sql = $conn->query("SELECT id FROM country WHERE countryName = '$name'");
    if ($sql->num_rows > 0)
    exit("Country With This Name Already Exists!");
    else {
    $conn->query("UPDATE country SET countryName='$name', shortDesc='$shortDesc', longDesc='$longDesc' WHERE id='$rowID'");
    exit('success');
    }
    }

    Now I only need to solve the Page update on adding a new Country!

    EDIT 3: I could not find a good solution for the table update. From what I know, I would have to use $('.table').draw(); but so far I have been unsuccessful in my endeavors. I'm using: window.location.reload(); to reload the page as a workaround. I placed it right under $("#manageBtn").attr('value', 'Add').attr('onclick', "manageData('addNew')");

    If anyone can find a good solution for this please give me a nice reply ๐Ÿ™‚

    EDIT 4: Sadly, the method used here can not update the table because the data is not parsed through Ajax, therefore we can not use ajax.reload() function. In this method, once the table has been initialized it cannot be re-initialized. The good news is that I found a tutorial that uses this: https://youtu.be/rSRGfXXVFxA – P.S. it has a robot voice but eh, what can you do!?

  2. Senaid You're awesome! The way you proceed , the way you explain stuff never missing out any details or functionality is unmatched and quite helpful for beginners like me. Keep Up the Good work mate! ๐Ÿ™‚
    I'm working on a college project and i'm using your model for the same i was wondering if i could add save as pdf button on clicking view button along side the close button. i know how to add the button as you showed by adding and fading it out on the other menus but how do i link the functions to onclickaction of that button. i'm trying to achieve it by tho but if i could get a bit of help that would be great.

  3. Really amazing. But i have a problem? You use pdo and i generally use simple mysql to connect with php. Can you tell me the basic syntax difference so i can change your code to simple mysql and use. I try to find out things but i didnt find it? i dont know whether you will reply or not but if you reply send me a copy to my email "mangla.vishu@gmail.com" thanks in advance

  4. Hi Senaid again, it looks like the draw() solution you suggested earlier does not work. Do you have another tip? I am trying to achieve table reload/refresh for both, deleteRow() and manageData() for update and add.
    Right now Add New will not refresh the table with the new entry. Also, I figured that $("#cat_"+editRowID.val()).html(name.val()); for Edit option is more of a workaround just for the Country field only.
    DeleteRow() needs the refresh too, because it doesnt update the "Showing 1 to 10 of XXX entries". XXX stays the same and doesn't decrease. I think that a complete reload can help all options: add, edit and delete.
    Please help!!

  5. What a wonderful work, Senaid! Your pace and continuity are simply amazing! At first I thought it was scripted with cheat sheets (which is ok), but sir, seeing how you pick your choices and build as you go, that is so impressive.
    I loved your tutorial and I am using it as a reference for my project. If you don't mind I wanted to ask you for just a guidance, not a ready solution on a plate… What would be your take on reusing this code for managing multiple tables of different size? I would hate to create a duplicate copy for each table, and instead try to reuse its functionality. Do you have any suggestions for me? I just need the approach and general cornerstone ideas. As for the rest I will do my research and find details "how to". Or maybe there is another tutorial that covers how to reuse functions and the recommended "architecture" – what to place where and how to tie everything in together. Something that I could use as inspiration and combine with this tutorial? Thank you sir and much much respect!

  6. Hi Senaid, Great tutorials once again! You are such a kind person for sharing your knowledge with us. I wanted to ask if you can create additional data entries that handle images too? It just handles all text data. Thank you ๐Ÿ™‚

  7. Senaid thanks for the great video. One question, you are deleting row from the Datatable , so it is not sending Ajax query to the MySql , refreshing and showing "real situation". Let me explain, when you delete table row, you don't have any more 10 entries, but 9, and deleting next one will leave us with 8, this issue will be much more visible if you have striped rows, one white, and underneath one gray, so, if you delete 2nd row, you will have 2 white next to each other, and that doesn't look nice. Any idea, update?

Leave a Reply