does anyone know how to assign a fetch_assoc () or a mysqli_fetch_array () to a variable?

1

Thanks for reading my post.

I've been trying to do an assignment to a variable from a fetch_assoc () or a mysqli_fetch_array (), this is my code:

$dba = mysqli_connect('localhost', 'root', '', 'prueba');

$salida = "";

$query = "SELECT * FROM Clientes WHERE idClientes=''";

if (isset($_POST['consulta'])) {
    $q = $dba->real_escape_string($_POST['consulta']);
    $query = "SELECT * FROM Clientes WHERE idClientes = '$q' ";
}

$resultado = $dba->query($query);

while($filas = $resultado->mysql_fetch_array(resultado)){
    $name = $filas['Nombre_Clientes'];
    $phone1 = $filas['Telefono1'];
    $mail1 = $filas['Email1'];
    $company = $filas['Compania'];
    $city1 = $filas['Ciudad1'];
    $state1 = $filas['Estado1'];
}

my second failed code for tests was

$dba = mysqli_connect('localhost', 'root', '', 'prueba');

$query = "SELECT * FROM Clientes WHERE idClientes=''";
if (isset($_POST['consulta'])) {
    $q = $dba->real_escape_string($_POST['consulta']);
    $query = "SELECT * FROM Clientes WHERE idClientes = '$q' ";
}
$resultado = $dba->query($query);

if ($resultado->num_rows>0) {

while ($filas = mysqli_fetch_array($resultado)){
    $name = $filas[1];
    $phone1 = $filas[2];
    $mail1 = $filas[3];
    $company = $filas[4];
    $city1 = $filas[5];
    $state1 = $filas[6];
}}else{}

SQL is not very complex

SELECT 'idClientes', 'Nombre_Clientes', 'Compania', 'Direccion1', 'Ciudad1', 'Estado1', 'Telefono1', 'Email1', 'Direccion2', 'Ciudad2', 'Estado2', 'Telefono2', 'Email2', 'RFC', 'Status' FROM 'clientes'

database and connection in perfect operation.

If the question is why I want to do this, it is because I follow the tutorial of a person and I managed to do that will show the records in text fields instead of a table, but now I do not know how to send the text field information to a variable because the way I capture the information in the text field is as follows

if ($resultado->num_rows>0) {

    $salida.="";

    while ($fila = $resultado->fetch_assoc()) {

        $salida.=" 

        <div id='datos'>
        <div class='form-group'>
        <label class='col-sm-3 control-label'>Nombre del Cliente</label>
            <div class='col-sm-5'>
                <input type='text' name='name' class='form-control' value=".$fila['Nombre_Clientes']."  disabled>
            </div>
        </div>";
}
}else{
     }

which works without any problem for visualization and not for storage, because I store by the method

   $name = mysqli_real_escape_string($dba, $_POST['name']);

Any help is welcome.

edit: attached new failed method:

if (isset($_POST['consulta'])) {
    $q = $dba->real_escape_string($_POST['consulta']);
    $query = "SELECT * FROM Clientes WHERE idClientes = '$q' ";
    $query1 = "SELECT Nombre_Clientes FROM Clientes WHERE idClientes = '$q' ";
    $query2 = "SELECT Telefono1 FROM Clientes WHERE idClientes = '$q' ";
    $query3 = "SELECT EMail1 FROM Clientes WHERE idClientes = '$q' ";
    $query4 = "SELECT Compania FROM Clientes WHERE idClientes = '$q' ";
    $query5 = "SELECT Ciudad1 FROM Clientes WHERE idClientes = '$q' ";
    $query6 = "SELECT Estado1 FROM Clientes WHERE idClientes = '$q' ";
}

$resultado = $dba->query($query);

$name = $dba->query($query1);
$phone1 = $dba->query($query2);
$mail1 = $dba->query($query3);
$company = $dba->query($query4);
$city1 = $dba->query($query5);
$state1 = $dba->query($query6);

$res1 = $name.'';
$res2 = $phone1.'';
$res3 = $mail1.'';
$res4 = $company1.'';
$res5 = $city1.'';
$res6 = $state1.''; 
    
asked by ulises.isc 11.11.2018 в 06:09
source

0 answers