how can I bring the records from a database with a select / select?

0

This is my html code I want to bring the registration data by means of the name EditClient.php

         Edit Client     

Edit Client

    <form action="editarCliente_submit" method="get" accept-charset="utf-8">

    </form>

    <br> <label>Nombre Del Cliente : </label>
    <select name="Clientes">
        <option value="1">ARL Sura</option>
        <option value="2">ARl Colmena</option>
        <option value="3">AXA</option>
        <option value="4">Clinica Sagrado Corazon</option>
        <option value="5">Clinica Rosario</option>
        <option value="6">EMP Colsanitas</option>
        <option value="7">EMP Medisanitas</option>
        <option value="8">EPM</option>
        <option value="9">HSVF Medellin</option>
        <option value="10">HSVF Rionegro</option>
        <option value="11">IPSI</option>
        <option value="12">Particular</option>
        <option value="13">Sky Ambulance</option>
        <option value="14">Seguros De Vida Suramericana</option>
        <option value="15">Coosalud</option>
        <option value="16">Quirofanos el tesoro</option>
        <option value="17">Hospital Pablo Tobon Uribe</option>
        <option value="18">EPS Sanitas</option>
        <option value="19">San Esteban</option>
        option
    </select></br>

    <br> <label>NIT : </label>
    <input type="text" name="user" placeholder="Ingrese el NIT del cliente" required size="30" maxlength="30" style="margin-left: 5%" /><br/>

    <br> <label style="margin-left: -10%"> ¿Se realizan RIPS?  </label>
    <input type="text" name="user" placeholder="" required size="10" maxlength="15"/><br/>

    <br><input type="submit" name="Modificar_Cliente" value ="Modificar" onclick="location='http://localhost/Aeroasistencia/Administracion/modificarCliente.php'" style="margin-right: 3%">

    <input type="submit" name="Nuevo_Cliente" value ="Nuevo" onclick="location='http://localhost/Aeroasistencia/Administracion/nuevoCliente.php'">

    <input type="submit" value="Volver" onclick="history.back(-1)" style="margin-left: 3%" />


    </table>
</center>

    
asked by Cristian Antonio Trujillo Gris 23.03.2018 в 14:29
source

2 answers

1

Using the library of jQuery you could make a request $.ajax() to bring the data of the DB according to <select> , then:

index.html

<script type="text/javascript">
  // agrego un evento para cada vez que se modifica el select
  $('select[name=Clientes]').on('change', function() {
    var value = $(this).val(); // obtengo el valor de dicho select
    $.ajax({
      method: 'POST',
      url: 'editarCliente.php',
      data: { cliente: value },
      success: function(data) {
        // acá muestro la info que viene de la DB en #resultado
        $('#resultado").text(data);
      }
    });
  });
</script>

<div id="resultado"></div>

EditClient.php

<?php
// corroboro que exista la variable
if (isset($_POST) && isset($_POST['cliente'])) {
  // acá hago la query para obtener los datos con la conexión que tengas
  // "SELECT * FROM clientes WHERE cliente = $_POST['cliente']"
  // lo asigno a una variable $resultado
  echo json_encode($resultado);
}
?>
    
answered by 23.03.2018 в 15:06
0

I do not understand your question much, you should document it a little better

If you want to bring the data and show them using html you should use this

Very basic example.

<?php
// Conectando, seleccionando la base de datos

$direcciondeServidor = "127.0.0.1";
$nombredeUsuario = "root";
$contrasena = "";

$NombreBaseDeDatos= "tu base de datos";


$link = mysql_connect($direcciondeServidor, $nombredeUsuario, $contrasena)
    or die('No se pudo conectar: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db($NombreBaseDeDatos) or die('No se pudo seleccionar la base de datos');

// Realizar una consulta MySQL
$query = 'SELECT * FROM Tabla donde tienes los registros';
$result = mysql_query($query) or die('Consulta fallida: ' . mysql_error());

// Imprimir los resultados en HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Liberar resultados
mysql_free_result($result);

// Cerrar la conexión
mysql_close($link);
?>

then so that the user can modify when clicking, you will have to make each row of record have a button (or convert the whole row into one) send the Id and create a modal or another page to modify

    
answered by 23.03.2018 в 15:04