how to use mysqli_fetch_array

Asked

Viewed 7,125 times

4

would like to know how I use this command mysql in my code because I’m trying and nothing I can’t make it work.

code:

 $sql = mysqli_query($mysqli, "SELECT * FROM produtos LIMIT $inicio, $totalProduto");
            while($aux = mysqli_fetch_array($mysqli, $sql)){
              $id = $aux['id_produto'];
              $nome = $aux['nome'];
              $desc = $aux['descricao'];
              $preco = $aux['preco'];
              $categoria = $aux['categoria'];
              $img = $aux['img'];
              $tipo = $aux['type'];
              $size = $aux['size'];
  • 1

    And what’s the problem? And I already see a crazy thing there that the local variables do not match the names of the members of the objects. It can, but it doesn’t make sense. Another problem is the use of $mysqli as a parameter.

1 answer

5


mysqli_fetch_array() receives only one argument which is the return of mysqli_query() and not the connection.

Change to:

 while($aux = mysqli_fetch_array($sql)){

When using Mysqli procedural style in ALMOST all functions the first argument is the connection, mysqli_fetch_*() is an exception to this rule.

View the function signature

Mixed mysqli_fetch_array ( mysqli_result $result [, int $resulttype = MYSQLI_BOTH ] )

Documentation - fetch_array()

Documentation - list of functions

  • vlw rray had not realized to me I would have to pass the connection together vlw function

  • 1

    @Leonardocosta, using the procedural style of mysqli ALMOST all functions the first argument is the connection, mysqli_fetch_() is an exception to this rule :P

  • intendi. vlw guy

Browser other questions tagged

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