PHP - How to sort lottery table values

Asked

Viewed 90 times

0

I have the following problem: -let’s imagine that we have the records of a lottery, but we need to sort the values. I have tried the documentation code of the php - asort, but it doesn’t work! I’m using the version 7.2.4 of php (I hope you don’t have a bug)!

Database: inserir a descrição da imagem aqui

I want to order the numbers that are in n1, n2, n3, n4, n5 and n6.

Ex: the record id=2032, should have n1=6, n2=14, n3=19, n4=20, n5=39 and n6=53.

Code:

$result = mysqli_query($db, "SELECT * FROM table32");
while ($dados = mysqli_fetch_array($result, MYSQLI_BOTH)) { 
    $valores = array(
        "n1" => $dados['n1'], "n2" => $dados['n2'], 
        "n3" => $dados['n3'], "n4" => $dados['n4'], 
        "n5" => $dados['n5'], "n6" => $dados['n6']
    );
    asort($valores);
    foreach ($valores as $n => $val) { 
        echo "$n = $val"; //Não chega aqui! 
    } 
}
  • Could provide the code you use to insert them into db?

  • $result = mysqli_query($db, "SELECT * FROM table32"); while ($dados = mysqli_fetch_array($result, MYSQLI_BOTH)) { $values = array("n1" => $data['n1'], "N2" => $data['N2'], "N3" => $data['N3'], "N4" => $data['N4'], "N5" => $data['N5']], "N6" => $data['N6']); asort($values); foreach ($values as $n => $val) { echo "$n = $val"; //Does not get here! } }

  • I think I figured it out, I had a problem connecting to the database. affff

  • If you have any questions about ordering arrays, I recommend: https://www.w3schools.com/php/showphp.asp?filename=demo_array_sort_num

No answers

Browser other questions tagged

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