Consult several tables

1

I am using the following code but it does not work for me. I'm trying to bring information from 3 tables:

 $result  = mysqli_query($con,"SELECT a.ID,a.proveedor,a.peso,a.fecha,b.ENTRADA,b.cajas,b.peso,b.pagado,c.ENTRADA,c.monto FROM a entradas b separacion c pagos WHERE b.ENTRADA=a.id AND c.ENTRADA=a.id") or mysqli_error($con);

    while ($row = $result->fetch_assoc()) {
         $arr[] = $row;
    }

The problem is that I run it from PostMan and it marks me:

<b>Fatal error</b>:  Call to a member function fetch_assoc() on a non-object in  <linea de error> while ($row = $result->fetch_assoc()) {
    
asked by DoubleM 30.01.2018 в 07:31
source

1 answer

1

The error may be because the query mysql is wrong.

You can use the JOIN of mysql statements. You can consult the documentation here

Here are some examples:

  

SELECT * FROM a JOIN b LEFT JOIN c ON (c.key = a.key) LEFT JOIN d ON   (d.key = a.key) WHERE b.key = d.key;

     

SELECT * FROM t1 LEFT JOIN t2 ON (column1) WHERE t2.column2 = 5;

All information is taken from the mysql documentation

    
answered by 30.01.2018 в 07:37