PHP I'm not going to the jquery function that I call

0

I have been working with php for a short time and I get confused about many things. I have a php program called classificacion.php that only reads a table with the data of a classification table, the 1st field is idclaf, which is the code with which I identify each team and I use it so that through Ajax, get the name of the team in a table called equipment (I do not know if it is the best way to do it, I do not think so). But when I call the function to do the Ajax, it does not enter the function, and of course, it does not bring me anything. Here the 2 codes:

classification.php

     <html lang="es">

<head>
    <meta charset="utf-8">

    <meta name="category" content="Prácticas">

    <title>Tabla de Clasificacion de la Liga de Futbol</title>
    <!-- Declaración de fichero de estilos -->
    <link rel="stylesheet" type="text/css" href="estilos/estilo.css">


    <script type="text/javascript" src="js/jquery.js"></script>

    <script language=javascript type="text/javascript">

            function solicitaNombre(codigo) {
                var parametros = { // pasamos los datos de opcion a parametros
                    "valorCodigo": codigo,
                }
                // aqui comienza a funcionar Ajax
                $.ajax({

                    data: parametros,
                    url: 'buscar_nombre.php',
                    type: 'post',
                    beforeSend: function () { // envio de la variable
                        $("#resp").html("Procesando, espere por favor..."); // mientra se procesa envia un mensaje
                    },
                    success: function (response) {
                        equipo = .html(response);
                        return equipo;
                    }
                })
            }


    </script>


</head>
<body>

<div class="general">
    <div class="sisnav">
        <span class="notsp00">HOME - &gt;</span>
    </div>
    <?php
    require("cabecera.php")
    ?>
    <div class="caja2">
        <section>
            <div class="cuerpo02">
                <h3>Clasificacion de la liga</h3><br/>
                <?php
                include("conexion.php");
                // selecionamos la base de datos
                if(mysqli_select_db($conn, $dbname) === TRUE) {


                    $sql = "SELECT * FROM clasificacion ORDER BY puntos DESC , dg DESC , gf DESC";

                    $result = mysqli_query($conn, $sql);

                    if ($result) {
                        // Si hay registros
                        if (mysqli_num_rows($result) !== 0) {
                            ?>

                            <table class="clasif" cellpadding="4" cellspacing="1" border="1">
                                <tr >
                                    <th >Equipo</th>
                                    <th>PJ</th>
                                    <th>G</th>
                                    <th>E</th>
                                    <th>P</th>
                                    <th>GF</th>
                                    <th>GC</th>
                                    <th>DG</th>
                                    <th>PTS</th>
                                </tr>
                                <?php
                                while ($row = mysqli_fetch_array($result)) {

                                    ?>

//aqui llama a la funcion
                                    <script language=javascript type="text/javascript">
                                        $( function() {
                                            solicitaNombre(<?php $row['idclaf'];?>);
                                        })
                                    </script>


                                    <tr>
                                        <td>equip</td>
                                        <td><?php echo $row['jugados'];?></td>
                                        <td><?php echo $row['ganados']; ?></td>
                                        <td><?php echo $row['empatados']; ?></td>
                                        <td><?php echo $row['perdidos']; ?></td>
                                        <td><?php echo $row['gf']; ?></td>
                                        <td><?php echo $row['gc']; ?></td>
                                        <td><?php echo $row['dg']; ?></td>
                                        <td><?php echo $row['puntos']; ?></td>
                                    </tr>
                                    <?php
                                }
                                ?>
                            </table>

                            <?php

                        }
                    }else{
                        echo "error";
                    }
                }



                ?>

            </div>
        </section>

    </div>

</div>

</div>

<?
mysqli_close($conn);

?>
</body>
</html>

search_name.php

    <?php
if( isset($_POST['valorCodigo']) ) { // Existe valorOpcion, es la variable que viene del ajax
    $codigo = $_POST['valorCodigo'];

    require("conexion.php");
    // selecionamos la base de datos
    if(mysqli_select_db($conn, $dbname) === TRUE) {
        $sql2 = "SELECT nombre   FROM equipos WHERE idequip = $codigo";

        $result2 = mysqli_query($conn, $sql2);
        if ($result2) {
            // Si hay registros
            if (mysqli_num_rows($result2) !== 0) {
                $fila2 = mysqli_fetch_assoc($result2);
                $equipo=  $fila2['nombre'];
                return $equipo;



            }
        }
    }

}
?>

.

    
asked by Buda 07.06.2017 в 09:38
source

1 answer

0

You already have the data, but you're not doing anything with it. Osea invoke a function, you pass a parameter, pick it up the other function makes your theater the AJAX, the value you return in a variable called equipment and you give return. Go back to the code that invoked the function and you do not do anything with that data anymore.

<script language=javascript type="text/javascript">
  $( function() {
  alert(solicitaNombre(<?php $row['idclaf'];?>));
  $('div').html(solicitaNombre(<?php $row['idclaf'];?>));
});
</script>

Do something with that data ...

    
answered by 07.06.2017 в 19:52