how can I show the data of a database by means of a select by means of the name

0
<?php  
    $conexion =  mysqli_connect("localhost", "root","admin123","database");
    $sentencia = "SELECT * FROM cliente order by  cliente asc";
    $query = mysqli_query($conexion,$sentencia);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Editar Cliente</title>
    <link rel="stylesheet" type="text/css" href="estilos.css">
</head>
<body>      
    <center>
        <table width="280" cellspacing="1" cellpadding="3" border="0" bgcolor="#1E679A">
        <h1>Editar Cliente</h1>

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

        </form>
        <br> <label>Nombre Del Cliente : </label>
        <select name="Clientes">

            <?php while ($arreglo = mysqli_fetch_array($query)) { ?>

            <option value="<?php echo $arreglo['nombre_Cliente']?>"><?php echo $arreglo ['NIT']?></option>

            <?php } ?>

            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>

</body>
</html>
    
asked by Cristian Antonio Trujillo Gris 23.03.2018 в 16:05
source

2 answers

0

You put this under your Query

$cliente = array();

while ($arreglo = mysqli_fetch_array($query)) 
{      
    $cliente[] = array(
        "nombre_Cliente" => $data['nombre_Cliente'],
        "nit" => $data['NIT'],
    );
}

Down in the select

if (count($cliente) > 0) //este es tu array con resultrados
{
    foreach ($cliente as $ti) 
    {
        echo "<option value='". $ti['nombre_Cliente'] ."'>". $ti['nit'] ."</option>";
    }
}

But I suggest that in the option value you indicate the id of your table.

Where it says Nit indicates the name and nit separated by a hyphen

    
answered by 23.03.2018 в 16:38
0

When you do the query, you can bring it in a json, then in the form

if (count($aTipoIndicador) > 0)    //este es tu array con resultrados
{
    echo "<option value=''>".$aIdioma['seleccione']."</option>";
    foreach ($aTipoIndicador as $ti) 
    {
        echo "<option value='". $ti['idTipoIndicadorencode'] ."' data-id='". $ti['idTipoIndicadorencode'] ."'>". $ti['nombreTipoIndicador'] ."</option>";
    }
} 
else
{
    echo "<option value=''>".$aIdioma['noHayTipoIndicador']."</option>";                                                
}
    
answered by 23.03.2018 в 16:13