There is some way to put this MySqli query together

1
   $pro1="Tubo Estructural";
   $pro2= "Protector De Corriente";

   $sql= "SELECT producto, SUM(cantidad) as monto FROM grafica WHERE producto = '$pro1' ";
   $query= mysqli_query($conexion,$sql);

   $sql1= "SELECT producto, SUM(cantidad) as monto FROM grafica WHERE producto = '$pro2'";
   $query1= mysqli_query($conexion,$sql1);

   $row=mysqli_fetch_array($query);
   $row1=mysqli_fetch_array($query1);

       echo $row['producto'].' '.$row['monto'];
        echo $row1['producto'].' '.$row1['monto'];

I clarify that is what I want if it works like this, but I see how to render information and I do not think it's the right way, is there a way to do all that in a single consultation?

    
asked by Steban De Abreu 11.10.2018 в 16:09
source

1 answer

1
  

We use the IN to tell you to search for records within   those two coincidences, then we indicate that you group them by name   of the product because we're using an aggregation function and then   we order the records by product

"SELECT producto, SUM(cantidad) as monto 
FROM grafica 
WHERE producto IN('$pro1', '$pro2') 
GROUP BY producto 
ORDER BY producto";
    
answered by 11.10.2018 / 16:25
source