Show all records in a column

-1

I made a query where I got the result of this query, however what I need is this result shows only one line, a single record but in reality I have more than one: follow the code below and please show me where I'm going wrong because I can not see the error or the lack of some element ..

if (empty($_POST['contrato'])) {"";} 
     if(isset($_POST['contrato'])) {"";
        if($_POST['contrato'] == "") {"";}
        else{   

            $cmd = "SELECT login FROM tecnicos GROUP BY Area = '%$Roteamento%' ";
            $login_tecnico = mysqli_query($conn, $cmd);

            $row = mysqli_num_rows($login_tecnico);

            if($row == " ") {" ";} else{

            while ($res = mysqli_fetch_array($login_tecnico)) {
            $tec_login = $res['login'];

Successfully displays the tec_loogin variable, but as I said this displays only 1 record when it actually has more than one, my question is how to display all of them ?? help me ...

    
asked by anonymous 11.10.2018 / 20:50

1 answer

1

This is happening because with each while loop, your code writes what is in $tec_login , so it only shows one record. You can concatenate everything in the same variable or store each login in an element of an array:

Concatenating:

$tec_login = '';
while ($res = mysqli_fetch_array($login_tecnico)) {
            $tec_login .= $res['login'].' ';
}

Array:

$tec_login = [];
while ($res = mysqli_fetch_array($login_tecnico)) {
            $tec_login[] = $res['login'];
}

The way your code is doing while , would be the same as, for example:

$tec_login = 'valor 1';
$tec_login = 'valor 2';
$tec_login = 'valor 3';

Where, after all, the value of the variable would be only 'valor3' .

    
11.10.2018 / 20:55