formulate query to show data

0

As I do so that in my table I throw the invoices that went to credit and cash since if I put an and in the query does not throw data to me because to say on a date there is only credit and in the query I ask both credit and counted data and I do not comply with the condition and if I put an or throw data but out of date.

<?php
include('conexion.php');
$fecha=$_POST['fecha'];
date_default_timezone_set('America/Mexico_City');
    //preguntamos la zona horaria
    $zonahoraria = date_default_timezone_get();
$hora=date ('G:i');
?>

<div align="center">
<font size="+2" color="#FFFFFF"><strong>FACTURAS Y REMISIONES DEL DIA: <?php echo $fecha?>, A LAS: <?php echo $hora?></strong></font>

<table class="tablafac">
<tr>
<th>FACTURA</th>
<th>TIPO DE PAGO</th>
<th>FECHA</th>
<?php
$fecha=$_POST['fecha'];
$query=mysql_query("SELECT factura,tipopago,fechafactura from facturacion WHERE fechafactura='$fecha' AND entregada='on' AND tipopago='CONTADO' OR tipopago='CREDITO'");
$contador =mysql_num_rows($query);
if($contador> 0)
{ 
while ($array=mysql_fetch_array($query))
 {  echo "<tr>
    <td>".$array[0]."</td>
    <td>".$array[1]."</td>
    <td>".$array[2]."</td>
    </tr>";
 }
 echo "</table>";
}
else
{
    echo "<tr>
    <td>No hay registros</td>
    </tr>
    </table>";
}
?>
    
asked by jasiel 31.10.2018 в 18:56
source

2 answers

1

The correct way to achieve what you want is using parentheses like this:

SELECT factura,tipopago,fechafactura 
from facturacion 
WHERE fechafactura='$fecha' AND entregada='on' AND (tipopago='CONTADO' OR tipopago='CREDITO')
    
answered by 31.10.2018 в 18:59
1

Try doing the query in the following way:

$query=mysql_query("SELECT factura,tipopago,fechafactura from facturacion WHERE fechafactura='$fecha' AND entregada='on' AND (tipopago='CONTADO' OR tipopago='CREDITO')");
    
answered by 31.10.2018 в 19:01