Array bringing different PHP results

Asked

Viewed 42 times

1

I have my comic book, however, is bringing me a different result than what is in the bank

$consulta = "select * FROM PRODUTO_pedido WHERE PEDIDO_PED_ID =12";                        
$resultado = $db_con->query($consulta);
$contador = $resultado ->rowCount(); 
while ($row = $resultado-> fetch()){
  echo "<script>alert(".$row['PRODUTO_PROD_CODIGO'].")</script>";
}

For example, in the comic the id is as 299007 and is showing me 01110105.

How do I resolve?

  • Already played this your query on the bank even to see the return?

  • Take a test and change the line while ($row = $resultado-> fetch()) for while ($noticia = mysql_fetch_assoc($query)).

1 answer

0

Use the method fetch_array instead of fetch. Your code will look like this:

$consulta = "select * FROM PRODUTO_pedido WHERE PEDIDO_PED_ID=12";                        
$resultado = $db_con->query($consulta);
$contador = $resultado ->rowCount(); 
while ($row = $resultado-> fetch_array()){
  echo "<script>alert(".$row['PRODUTO_PROD_CODIGO'].")</script>";
}

Using fetch_array, you make it explicit that you want to treat each line of the result of query as a array separately within the repeat loop.

Here is the documentation:

https://secure.php.net/manual/en/mysqli-result.fetch-array.php

To use fetch, you need to determine an association (as seen in the documentation: php.net/manual/en/mysqli-stmt.fetch.php):

stmt_bind_assoc($db_con, $row);

Browser other questions tagged

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