PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] filter duplicate rows with cake php and java script

 March 15, 2022     cakephp-3.0, javascript, php     No comments   

Issue

I'm trying to filter table which is append using java script with cake php frame work . and the following code is for adding this tables when i have click on add new magazine ,, but the problem is that , It's add double rows which has been added before . So i need to filter the added rows to delete the duplicated row.

/// function to show magazines data table
    $('#add_researches_button').click(function () {
        $("input[name='bstock_researchs_id[]']:checked").each(function (i) {
            val[i] = $(this).val();

        });
        $.ajax({
            type: "POST",
            url: '../BstockIn/getResearchesIds/' + val,
            dataType: "json",
            success: function (data) {
                $('#researches').css('display', 'block');

                var res = $.parseJSON(data);

                var CountResearches = 0;

                jQuery.each(res, function (index, value) {

                    CountResearches++;

                    $("#researches").append("<tr><td>"
                            + value.research_serial +
                            "</td><td>"
                            + value.research_release_date +
                            "</td><td>"
                            + value.research_release_hejry_date +
                            "</td><td>"
                            + value.research_pages +
                            "</td><td>"
                            + value.research_copies +
                            "</td></tr>"

                            );


                });

Solution

/// function to show magazines data table
$('#add_researches_button').click(function() {
      $("input[name='bstock_researchs_id[]']:checked").each(function(i) {
        val[i] = $(this).val();

      });
      $.ajax({
            type: "POST",
            url: '../BstockIn/getResearchesIds/' + val,
            dataType: "json",
            success: function(data) {
                $('#researches').css('display', 'block');

                var res = $.parseJSON(data);

                var CountResearches = 0;

                jQuery.each(res, function(index, value) {

                  CountResearches++;
                  if ($("#researches tr[data-id='" + value.research_serial + "']").length == 0)
                    $("#researches").append("<tr data-id='" + value.research_serial + "'><td>" +
                      value.research_serial +
                      "</td><td>" +
                      value.research_release_date +
                      "</td><td>" +
                      value.research_release_hejry_date +
                      "</td><td>" +
                      value.research_pages +
                      "</td><td>" +
                      value.research_copies +
                      "</td></tr>"

                    );


                });


Answered By - Brahma Dev
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing