Data output from MySQL database

I have a piece of code

$query = "SELECT id, name, lastname, bykva FROM uchenik WHERE bykva='$bykva' AND class=$class";  
$result = mysql_query($query) or die(mysql_error()); $users = array();  
while($row=mysql_fetch_array($result)){
    $uc = $row["lastname"] ." ". $row["name"];
    $id = $row["id"];
    $users[] = "$uc";       
}

If you take $row=mysql_fetch_array($result)without a loop and output, then it outputs the students you need. Example:

Array ( [0] => 1 [id] => 1 [1] =>  [name] =>  [2] =>  [lastname] =>  [3] =>  [bykva] =>  )

But in the loop, he makes 2 arrays, 1 for those students that I need, and 2 for the rest. And it already assigns all the students to my $users array, not the ones I need. Example:

Array ( [0] => 1 [id] => 1 [1] =>  [name] =>  [2] =>  [lastname] =>  [3] =>  [bykva] =>  ) Array ( [0] => 2 [id] => 2 [1] =>  [name] =>  [2] =>  [lastname] =>  [3] =>  [bykva] =>  )

How can I make it make only the students I need in the loop


Answer 1, authority 100%

Change

$row=mysql_fetch_array($result)

to

$row=mysql_fetch_assoc($result)

remove $users[] = "$uc";

P.S.

It is not clear why you are passing the $bykvavariable to the request and getting the letter by the request.


Answer 2

Correctly format the SQL query, in accordance with what exactly you need to get at the output.