title: Error in console output for json_encode to display the result in console?
body: <p>FYI, I am working on localhost with wampserver, using PHP and AJAX, trying to display the JSON data rows (which are around 1526). and the problem is i am not able to display the rows which are based on the search conditions.</p>
  
  <p>Output of <code>print_r($result_array);</code> in console output as below. here in below pic don't worry for console error this error is becoz of PHP array used in parsing JSON. This output i used to test weather my server PHP file is working correctly or not but it is working correctly.</p>
  
  <p><a href="https://i.stack.imgur.com/B6MYz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6MYz.png" alt="enter image description here"></a></p>
  
  <p>After that i checked my encoding function, for which output of <code>echo json_encode($result_array);</code> i am getting red console error for some search condition and in other search condition i am able to display results correctly.
  For example, below two images</p>
  
  <p><a href="https://i.stack.imgur.com/UhOm2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UhOm2.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/49H5a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/49H5a.png" alt="enter image description here"></a></p>
  
  <p><strong>I am not able to figure out what is happening to my code.</strong></p>
  
  <p>File <code>search.php</code></p>
  
  <pre><code>
  &lt;?php 
  
          // send a JSON encoded array to client
  
          include('connection.php');
  
          $sqlFlag = 0;
  
          function queryDelimiter(){
              global $sqlFlag;
              if ($sqlFlag == 0){
                  $sqlFlag = 1;
                  return ' WHERE ';
              }else{
                  return ' AND ';
              }
          }
  
          $selectSQL = "SELECT * FROM tbl_main_lead_info";
  
          if(isset($_POST['lead_status']) and strlen(trim($_POST['lead_status'])) &gt; 0){
              $selectSQL .= queryDelimiter()."LeadStatus = '".$_POST['lead_status']."'";
          }
  
          if(isset($_POST['lead_owner']) and strlen(trim($_POST['lead_owner'])) &gt; 0){
              $selectSQL .= queryDelimiter()."LeadAddedBy = '".$_POST['lead_owner']."'";
          }
  
          if(isset($_POST['company_name']) and strlen(trim($_POST['company_name'])) &gt; 0){
              $selectSQL .= queryDelimiter()."Company = '".$_POST['company_name']."'";
          }       
  
          if(isset($_POST['tech_area']) and strlen(trim($_POST['tech_area'])) &gt; 0){
              $selectSQL .= queryDelimiter()."TechArea = '".$_POST['tech_area']."'";
          }
  
          if(isset($_POST['firm_size']) and strlen(trim($_POST['firm_size'])) &gt; 0){
              $selectSQL .= queryDelimiter()."FirmSize = '".$_POST['firm_size']."'";
          }
  
          if(isset($_POST['firm_type']) and strlen(trim($_POST['firm_type'])) &gt; 0){
              $selectSQL .= queryDelimiter()."FirmType = '".$_POST['firm_type']."'";
          }
  
          if(isset($_POST['country_name']) and strlen(trim($_POST['country_name'])) &gt; 0){
              $selectSQL .= queryDelimiter()."Country = '".$_POST['country_name']."'";
          }
  
          if(isset($_POST['state_name']) and strlen(trim($_POST['state_name'])) &gt; 0){
              $selectSQL .= queryDelimiter()."State = '".$_POST['state_name']."'";
          }
  
          if(isset($_POST['city_name']) and strlen(trim($_POST['city_name'])) &gt; 0){
              $selectSQL .= queryDelimiter()."City = '".$_POST['city_name']."'";
          }
  
          if(isset($_POST['start_date']) and strlen(trim($_POST['start_date'])) &gt; 0){
              $selectSQL .= queryDelimiter()."LastContactDate &gt;='".$_POST['start_date']."'";
          }
  
          if(isset($_POST['end_date']) and strlen(trim($_POST['end_date'])) &gt; 0){
              $selectSQL .= queryDelimiter()."NextContactDate &lt;= '".$_POST['end_date']."'";
          }
  
          $selectSQL .= " ORDER BY FirstName ASC, LastName ASC, Lead_Id ASC";
  
          $result_array = array();
  
          $result = $conn -&gt; query ($selectSQL);
  
          if(mysqli_num_rows($result) &gt; 0){
  
              while ($row = $result-&gt;fetch_assoc()) {
  
                  array_push($result_array, $row);
  
              }
  
          }
  
          // print_r($result_array);
  
          echo json_encode($result_array);
  
          // $selectSQL = "SELECT * FROM tbl_main_lead_info as M, tbl_campaign_info as C";
  
          $conn-&gt;close();
  
  ?&gt;
  
  </code></pre>
  
  <p>File <code>loadtable.js</code></p>
  
  <pre><code>// This is script to load table based on filter section
  
  $(document).ready(function() {
  
      // Campaign Submit Info
      $('[name="search_submit"]').click(function(e) {
  
          $('#load-csv-file-button').attr('style','display:none;');
          $("#filterRecords").attr('style','display:block;');
          $('#add_lead_info').attr('style','display:none;');
  
          e.preventDefault();
  
          // GET the admin and user id value
          var adminvalue = $('#filterformpost').find('[name="adminvalue"]').val();
          var useridvalue = $('#filterformpost').find('[name="useridvalue"]').val();
  
          var lead_owner = $('#filterformpost').find('#lead_owner_select option:selected').val();
          var lead_status = $('#filterformpost').find('#lead_status_select option:selected').val();
  
          var company_name = $('#filterformpost').find('#company_name_select option:selected').val();
          var tech_area = $('#filterformpost').find('#tech_area_select option:selected').val();
          var firm_size = $('#filterformpost').find('#firm_size_select option:selected').val();
          var firm_type = $('#filterformpost').find('#firm_type_select option:selected').val();
          var country_name = $('#filterformpost').find('#country_name_select option:selected').val();
  
          var city_name = $('#filterformpost').find('#city_name_select option:selected').val();
  
          var state_name = $('#filterformpost').find('#state_name_select option:selected').val();
          var start_date = $('#filterformpost').find('#start_date_search').val();
          var end_date = $('#filterformpost').find('#end_date_search').val(); 
  
          // console.log('adminvalue: '+adminvalue)
          // console.log('useridvalue: '+useridvalue)
          // console.log('lead_owner: '+lead_owner)
  
          // console.log('country_name: '+country_name)
          // console.log('State: '+state_name)
  
          $.ajax({
                type: "POST",
                url: "./server/search.php",
                data: {
                    "lead_owner": lead_owner,
                    "lead_status": lead_status,                
                    "company_name": company_name,
                    "tech_area": tech_area,
                    "firm_size": firm_size,
                    "firm_type": firm_type,
                    "country_name": country_name,
                    "city_name": city_name,
                    "state_name": state_name,
                    "start_date": start_date,
                    "end_date": end_date
                },
                beforeSend: function() {
  
                    $('.search_lead_filter_message_box').html(
                        '&lt;img src="tenor.gif" width="40" height="40"/&gt;'
                    );
                },
                success:function(data){   
  
                    // console.log(data)
  
                    console.log("Data Length: "+data.length)
  
                    console.log(data)
  
                    if(data.length == 0){
  
                       $('.search_lead_filter_message_box').html('');
                       $("#filterRecords").html('No results fetched');
  
                    }
  
                    var result = $.parseJSON(data);
                    // console.log(result)       
  
                    //###########################################
                    // Pagination code start
                    //###########################################
  
                    $('.search_lead_filter_message_box').html('');
  
                    $("#filterRecords").empty();
  
  
                    //###########################################
                    // Pagination code end
                    //###########################################
  
                    $("#pagination").attr('style', 'display:block;');   
  
                    $("#number_of_rows").attr('style','display:block;');
                    $('#button-prev-next').attr('style','display:block;');                                
  
                    paginate_json_data(result, adminvalue, useridvalue)
  
                }           
  
            });         
  
      });    
  
  });
  
  function paginate_json_data(userDetails, adminvalue, useridvalue) {
  
      adminvalue = adminvalue
      useridvalue = useridvalue
      userDetails = userDetails
  
      var table = '';
      table = $("&lt;table&gt;&lt;/table&gt;");    
  
      $('#pagination').html('&lt;div id="nav-numbers" class="col nav"&gt;&lt;/div&gt;'); 
  
      $('#number_of_rows').html('');
      $('#number_of_rows').html('&lt;p1&gt;Total number of leads fetched: ' + userDetails.length + '&lt;/p1&gt;');
  
      $('#button-prev-next').html('&lt;button class="col PreviousButton" id="PreValue"&gt;&lt;i class="ion-skip-backward"&gt;&lt;/i&gt; Previous&lt;/button&gt;&lt;button class="col NextButton" id="nextValue"&gt;Next &lt;i class="ion-skip-forward"&gt;&lt;/i&gt;&lt;/button&gt;');
  
      var max_size = userDetails.length;
      var sta = 0;
      var elements_per_page = 10;
      var limit = elements_per_page;
  
      if(max_size&lt;10){
  
        // #####################################
        // NUMBER OF ROWS A &lt; 10 START START
        // #####################################
  
        table.append('&lt;thead&gt;&lt;th&gt;#&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Company&lt;/th&gt;&lt;th&gt;Website&lt;/th&gt;&lt;th&gt;Designation&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;th style="width: 150px;"&gt;Phone&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;Country&lt;/th&gt;&lt;th&gt;Lead Status&lt;/th&gt;&lt;/thead&gt;');
  
        table.append('&lt;tbody id="myTable"&gt;&lt;/tbody&gt;');
  
        goFun_Modified(sta, max_size);
  
        function goFun_Modified(sta, limit) {            
  
          for (var i = sta; i &lt; limit; i++) {         
  
             var tab = '&lt;tr&gt;&lt;td&gt;' + (i+1) + "\n" + '&lt;/td&gt;&lt;td&gt;' + "&lt;a target='_blank' href=./lead/index.php?lead_id=" + userDetails[i].Lead_Id + " &lt;/a&gt;" + userDetails[i].FirstName + ' ' + userDetails[i].LastName + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Company + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Website + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Designation + "\n" + '&lt;/td&gt;&lt;td&gt;' + "&lt;a href=mailto:" + userDetails[i].Email + "&gt;" + userDetails[i].Email + "&lt;/a&gt;" + "\n" + '&lt;/td&gt;&lt;td style="width: 150px;" &gt;' + userDetails[i].Phone + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].City + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].State + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Country + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].LeadStatus + "\n" + '&lt;/td&gt;&lt;/tr&gt;';
  
             console.log(tab)               
  
            $('#myTable').append(tab)
  
          }
        } // Function ended      
  
        $("#filterRecords").html(table);
  
        $('#nextValue').click(function() { 
  
            // checks if it's the last page
            if (currentPage &lt; maxPage) {
              currentPage++;
              $pagingBtn.removeClass('active');
              $pagingBtn.eq(currentPage).addClass('active')
            } else {
              alert("End of page");
            }                     
  
        });
  
        $('#PreValue').click(function() {  
  
          // checks if it's the first page
          if (currentPage &gt; 0) {
            currentPage--;
            $pagingBtn.removeClass('active');
            $pagingBtn.eq(currentPage).addClass('active')
          } else {
            alert("Start of page")
          }     
  
        });
  
        var number = Math.round(userDetails.length / elements_per_page);
  
        for (i = 0; i &lt;= number; i++) {
  
          $('.nav').append('&lt;button class="nav-numbers btn" id=' + i + '&gt;' + (i+1) + '&lt;/button&gt;');
  
        }
  
        $('.nav button').click(function() {
  
          var start = $(this).text()-1;
  
          // $(this).css({"background-color": "#e67e22", "color": "#ffffff"});
  
          $('#myTable').empty();
  
          limit = 10 * (parseInt(start) + 1) &gt; max_size ? max_size : 10 * (parseInt(start) + 1)
  
          goFun_Modified(start * 10, limit);
  
          let $self = $(this);
          // gets index of button relative to it's siblings
          // https://api.jquery.com/index/
          currentPage = $self.index();
          $pagingBtn.removeClass('active');
          $self.addClass('active');
  
        });
  
        // saves all the paging buttons for reusing, instead of calling $() every time
        let $pagingBtn = $('#nav-numbers .btn');
        let maxPage = $pagingBtn.length - 1;
        let currentPage = 0;
  
        $('.nav button')[0].click()
  
        // #####################################
        // NUMBER OF ROWS A &lt; 10 END
        // #####################################
  
      }else{
  
          // #####################################
          // NUMBER OF ROWS A &gt; 10 START
          // #####################################  
  
          table.append('&lt;thead&gt;&lt;th&gt;#&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Company&lt;/th&gt;&lt;th&gt;Website&lt;/th&gt;&lt;th&gt;Designation&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;th&gt;Phone&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;Country&lt;/th&gt;&lt;th&gt;Lead Status&lt;/th&gt;&lt;/thead&gt;');
  
          table.append('&lt;tbody id="myTable"&gt;&lt;/tbody&gt;');
  
          goFun(sta, limit);
  
          function goFun(sta, limit) {
  
            for (var i = sta; i &lt; limit; i++) {           
  
             var tab = '&lt;tr&gt;&lt;td&gt;' + (i+1) + "\n" + '&lt;/td&gt;&lt;td&gt;' + "&lt;a target='_blank' href=./lead/index.php?lead_id=" + userDetails[i].Lead_Id + " &lt;/a&gt;" + userDetails[i].FirstName + ' ' + userDetails[i].LastName + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Company + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Website + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Designation + "\n" + '&lt;/td&gt;&lt;td&gt;' + "&lt;a href=mailto:" + userDetails[i].Email + "&gt;" + userDetails[i].Email + "&lt;/a&gt;" + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Phone + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].City + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].State + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].Country + "\n" + '&lt;/td&gt;&lt;td&gt;' + userDetails[i].LeadStatus + "\n" + '&lt;/td&gt;&lt;/tr&gt;';
  
              $('#myTable').append(tab)
  
            }
  
            $("#filterRecords").html(table);
  
          }// FUNCTION ENDED
  
          $('#nextValue').click(function() {
  
            var next = limit;
            if (max_size &gt;= next) {
  
              def = limit + elements_per_page;
  
              limit = def
  
              $('#myTable').empty();
  
              if (limit &gt; max_size) {
  
                def = max_size;
  
              }
  
              goFun(next, def);
  
            }   
  
            // checks if it's the last page
            if (currentPage &lt; maxPage) {
              currentPage++;
              $pagingBtn.removeClass('active');
              $pagingBtn.eq(currentPage).addClass('active')
            } else {
              alert("End of page");
            }
  
          });
  
          $('#PreValue').click(function() {
  
            var pre = limit - (2 * elements_per_page);
            if (pre &gt;= 0) {
  
              limit = limit - elements_per_page;
              $('#myTable').empty();
              goFun(pre, limit);
  
            }
  
            // checks if it's the first page
            if (currentPage &gt; 0) {
              currentPage--;
              $pagingBtn.removeClass('active');
              $pagingBtn.eq(currentPage).addClass('active')
            } else {
              alert("Start of page")
            }
  
          });
  
          var number = Math.round(userDetails.length / elements_per_page);
  
          for (i = 0; i &lt;= number; i++) {
  
            $('.nav').append('&lt;button class="nav-numbers btn" id=' + i + '&gt;' + (i+1) + '&lt;/button&gt;');
  
             if(i == number){
  
            }          
  
          }       
  
          $('.nav button').click(function() {
  
            var start = $(this).text()-1;
  
            $('#myTable').empty();
  
            limit = 10 * (parseInt(start) + 1) &gt; max_size ? max_size : 10 * (parseInt(start) + 1)
  
            goFun(start * 10, limit);
  
            let $self = $(this);
            // gets index of button relative to it's siblings
            // https://api.jquery.com/index/
            currentPage = $self.index();
            $pagingBtn.removeClass('active');
            $self.addClass('active');
  
          });
  
          // saves all the paging buttons for reusing, instead of calling $() every time
          let $pagingBtn = $('#nav-numbers .btn');
          let maxPage = $pagingBtn.length - 1;
          let currentPage = 0;
  
          $('.nav button')[0].click()
  
          // #####################################
          // NUMBER OF ROWS A &gt; 10 END
          // ##################################### 
  
        }
  
    }
  
  </code></pre>
  
  <p><strong>Updated:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/i5Ev3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i5Ev3.png" alt="enter image description here"></a></p>