Include comma in results from the database

1

I have a table where the structure is as follows:

  

IDEstoques | Product IDs | Sizes | Colors | Stocks

In it storing the sizes, colors and stocks of each product. However I need to bring the following information from the database:

Tamanhos: P,M, G    
Cores: Azul, Amarelo, Vermelho

I was able to bring only the sizes as follows:

$sqlEstoques = mysqli_query($this->conexao,"SELECT * FROM loja_estoques WHERE IDProdutos = '".$jmBusca->IDProdutos."';");

if(mysqli_num_rows($sqlEstoques) > 0){
   $resultado = array();
   while($jmEstoques = mysqli_fetch_array($sqlEstoques)){
         $resultado[] = $jmEstoques["Tamanho"];
   }
    $visualizar .= "<div class='col-lg-12' style='font-size: 14px; text-align: left'><strong>Tamanhos:</strong>". implode(",",$resultado);
    $visualizar .= "</div>";
}

Saída: Tamanho: P,M,G

How would I do to bring the colors too?

Cores: Azul, Amarelo, Vermelho
    
asked by anonymous 12.11.2017 / 23:06

1 answer

1

While you iterate, save in another variable the colors:

$sqlEstoques = mysqli_query($this->conexao,"SELECT * FROM loja_estoques WHERE IDProdutos = '".$jmBusca->IDProdutos."';");

if(mysqli_num_rows($sqlEstoques) > 0){
   $tamanhos= array();
   $cores= array();
   while($jmEstoques = mysqli_fetch_array($sqlEstoques)){
       $tamanhos[] = $jmEstoques["Tamanho"];
       $cores[] = $jmEstoques["Cores"];
   }
   $visualizar .= "<div class='col-lg-12' style='font-size: 14px; text-align: left'><strong>Tamanhos:</strong>". implode(",",$tamanhos)."</div>";
   $visualizar .= "<div class='col-lg-12' style='font-size: 14px; text-align: left'><strong>Cores:</strong>". implode(",",$cores)."</div>";
}

I recommend that you study the logic part of the programming a bit, I see that some basic concepts are missing. Read a few questions about security, especially how to avoid SQL Injection in PHP .

    
12.11.2017 / 23:31