SQL query with "left join" and an "if" in PHP [closed]

1

I have this query:

$customers_query_raw = "select ex.codigo_op, ep.entrega01_clave, ep.descripcion_articulo, ep.entrega01_envases, ep.entrega01_importe from " . TABLE_EXPORT_PATRIMONIO . " ep left join " . TABLE_EXPORT_COMPARATIVA_PATRI . " ex on ex.clave_patri = ep.entrega01_clave where ep.entrega01_envases <> '' and ep.num_envases <> '0' and ep.entrega01_indicaciones = 'null'";

And I need to insert this in the previous query and I do not know where to insert it to be fulfilled:

if ($customers['codigo_op'] == 'null'

This is my complete code:

<?php $customers_query_raw = "select ex.codigo_op, ep.entrega01_clave, ep.descripcion_articulo, ep.entrega01_envases, ep.entrega01_importe from " . TABLE_EXPORT_PATRIMONIO . " ep left join " . TABLE_EXPORT_COMPARATIVA_PATRI . " ex on ex.clave_patri = ep.entrega01_clave where ep.entrega01_envases <> '' and ep.num_envases <> '0' and ep.entrega01_indicaciones = '' and ex.codigo_op = ''";
    $customers_query = tep_db_query($customers_query_raw);

    while ($customers = tep_db_fetch_array($customers_query)) {
    if ($customers['codigo_op'] == '')  { ?>
    <td class="pageHeading_red_peque">Indicación!</td>
    <td><?php echo $customers['entrega01_clave']; ?></td>
    <td><?php echo $customers['descripcion_articulo']; ?></td>
    <td align="center"><?php echo $customers['entrega01_envases']; ?></td>
    <td><?php echo $customers['entrega01_indicaciones']; ?></td>
    <?php } ?>

to this code I need to add a count of this result.

//TABLE_EXPORT_PATRIMONIO
| entrega01_clave | entrega01_envases | entrega01_indicaciones  |
| xx.xx.xx.xx.xx  | 20                | blanco          |
| yy.yy.yy.yy.yy  | 30                |             |
| zz.zz.zz.zz.zz  | 0                 |             |

//TABLE_EXPORT_COMPARATIVA_PATRI
| clave_patri    | codigo_op |
| xx.xx.xx.xx.xx |   aaaaa   |
| yy.yy.yy.yy.yy |           |
| zz.zz.zz.zz.zz |   ccccc   |

what the counter is: from this query:

$customers_query_raw = "select ex.codigo_op, ep.entrega01_clave, ep.descripcion_articulo, ep.entrega01_envases, ep.entrega01_importe from " . TABLE_EXPORT_PATRIMONIO . " ep left join " . TABLE_EXPORT_COMPARATIVA_PATRI . " ex on ex.clave_patri = ep.entrega01_clave where ep.entrega01_envases <> '' and ep.num_envases <> '0' and ep.entrega01_indicaciones = 'null'";

count how many users have ex.codigo_op = Empty

    
asked by Ivan Diaz Perez 08.08.2017 в 12:13
source

0 answers