While inside of While

Asked

Viewed 206 times

1

I was trying to list a result of a select within another while but it only runs the second while once. That’s what I tried to do.

$lojas = query("Select cliente,endereco_cliente,cidade_cliente,uf_cliente,cep_cliente,cnpj_cliente from cliente LIMIT 4;");

while (($dados = fgetcsv($fp, 0, ";")) !== FALSE) {
    $quant_campos = count($dados);
    for ($i = 0; $i < $quant_campos; $i++) {
        echo "</br>".$dados[$i]; 
        while ($row = $lojas->fetch_assoc()) {
            echo "</br>BD:".$row['cnpj_cliente'];       
        }      
    }
    echo count($dados);
}
  • 1

    Sure you have more than one store in the return of your select?

1 answer

0

You should not use the fetch_assoc() > "while ($row = $lojas->fetch_assoc()).

To search all records, use the mysql_fetch_array():

while($row =  mysql_fetch_array($lojas)) { ... }

The fetch_assoc() is most used when the query returns a single record, usually when you search directly for the primary key.

Browser other questions tagged

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