View all records in a column

Asked

Viewed 68 times

-1

made a query where I got the result of this query, however what I need is this result displays only one line, a single record but in reality you more than one: follow the code below and please show me where I am missing because I can’t see the error or the lack of any 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 variable tec_loogin, but as said this displays only 1 record when actually has more than one, my question is how to display all?? help me...

  • You are grouping all results with Area = Routing, if all your records are like this, you will certainly return a single result, try using WHERE

  • I have done so, unsuccessfully.

  • I just want to make a query and through it display all the results of the column understand.

  • you can show some values that are in the column Area?

  • yes can, these are areas: AREA 05 AREA 06 AREA 24 AREA 25 AREA 30 AREA 31 AREA20 , and each area has its login.

1 answer

1


This is happening because with each repetition of the while, your code rerscribes what is in $tec_login, so it will only show a record. You can concatenate everything into that same variable or save each login into an array element:

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 thing as, for example:

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

Where, in the end, the value of the variable would be only 'valor3'.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.