0
I have two functions that are triggered from the moment the user enters a product code, but they are conflicting, can anyone tell me what to do ? For, within the JSON, in Inspect => Network Tab, have these results that would be the ones that should fill the tables. I’m suspecting this line $("table tbody") ... 
This should return within the first table
[{"recnum":"66","un_medida":"BD","operacao":"11.00","fator":"12.0000","default_venda":"13","fator_carga":"14.0000"}]
This should return inside the 2nd table
[{"id":"516","codigo_tipo":"4","descricao":"5"},{"id":"517","codigo_tipo":"7","descricao":"7"},{"id":"518","codigo_tipo":"9","descricao":"9"}]
But I’m getting back to it
Index.php
$(document).ready(function(){
            $("input[name='codigo_produto']").on("change", function(){
                    $.getJSON('function_pro-1.php',{ 
                            codigo_produto: $( this ).val(),
                            executar : 2
                            },function( json ){
                                var x = "";
                                    for (var i = 0; i < json.length; i++) {
                                        x += '<tr>';
                                            x += '<input type="hidden" name="recnum[]" value="'+json[i].recnum+'" style="border:none; width:100%; background-color: transparent;">';
                                            x += '<td><input type="text" name="un_medida[]" value="'+json[i].un_medida+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                            x += '<td><input type="text" name="operacao[]" value="'+json[i].operacao+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                            x += '<td><input type="text" name="fator[]" value="'+json[i].fator+'" style="border:none; width:100%; background-color: transparent;"/></td>';     
                                            x += '<td><input type="text" name="default_venda[]" value="'+json[i].default_venda+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                            x += '<td><input type="text" name="fator_carga[]" value="'+json[i].fator_carga+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                        x += '</tr>';
                                    }
//
                                $("table tbody").html(x);
                        });
                });
        });
    $(document).ready(function(){
                $("input[name='codigo_produto']").on("change", function(){
                        $.getJSON('function_pro-1.php',{ 
                                codigo_produto: $( this ).val(),
                                executar : 3
                        },function( json ){
                                var html = "";
                                    for (var i = 0; i < json.length; i++) {
                                        html += '<tr>';
                                        html += '<input type="hidden" name="id[]" value="'+json[i].id+'" style="border:none; width:100%; background-color: transparent;">';
                                        html += '<td><input type="text" name="codigo_tipo[]" value="'+json[i].codigo_tipo+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                        html += '<td><input type="text" name="descricao[]" value="'+json[i].descricao+'" style="border:none; width:100%; background-color: transparent;"/></td>';
                                        html += '</tr>';
                                    }
                                $("table tbody").html(html);
                        });
                });
        });
function_pro-1.php
function convunid($codigo_produto, $conn){
           $result = "SELECT * FROM CONVUNID WHERE codigo_produto = '$codigo_produto' ";
           $resultado = $conn->query($result);
           // DECLARA A VARIAVEL
           $valores = array();
        if($resultado){
            $row = mysqli_fetch_assoc($resultado);
            $novo['recnum'] = $row['recnum'];
            $novo['un_medida'] = $row['un_medida'];
            $novo['operacao'] = $row['operacao'];    
            $novo['fator'] = $row['fator'];
            $novo['default_venda'] = $row['default_venda'];
            $novo['fator_carga'] = $row['fator_carga'];
            array_push($valores, $novo);
        } else {
         return json_encode(array( 'error' => mysqli_error($conn) ));        
        }
         return json_encode($valores);
    }
    $opc = isset($_GET['executar']) ? (int) $_GET['executar'] : 0;
     if($opc === 2){
        echo convunid($_GET['codigo_produto'], $conn);
    }
 /* ---------------------------------------TIPOPROD---------------------------------------------------------------------- */    
     function tipoprod($codigo_produto, $conn){
        $result = "SELECT * FROM tipoprod WHERE codigo_produto = '$codigo_produto' ";
        $resultado = mysqli_query($conn, $result);
        // DECLARA A VARIAVEL
        $valores = array();
        if($resultado){
            while( $row = mysqli_fetch_assoc($resultado)){
                $novo['id'] = $row['id'];
                $novo['codigo_tipo'] = $row['codigo_tipo'];
                $novo['descricao'] = $row['descricao'];
                array_push($valores, $novo);
            }
        } else {
            return json_encode(array( 'error' => mysqli_error($conn) ));        
        }
        return json_encode($valores);                
    }
    $opc = isset($_GET['executar']) ? (int) $_GET['executar'] : 0;
    if($opc === 3){
        echo tipoprod($_GET['codigo_produto'], $conn);
    }
						