Foros del Web » Programando para Internet » PHP »

consulta fecha

Estas en el tema de consulta fecha en el foro de PHP en Foros del Web. Alguien me puede decir si ve un error en esto? Estoy intentando mostrar los registros en que la diferencia entre la fecha en la tabla ...
  #1 (permalink)  
Antiguo 31/12/2011, 06:46
 
Fecha de Ingreso: octubre-2011
Mensajes: 18
Antigüedad: 12 años, 6 meses
Puntos: 0
consulta fecha

Alguien me puede decir si ve un error en esto?
Estoy intentando mostrar los registros en que la diferencia entre la fecha en la tabla i la fecha de hoy este entre 30 dias.
Gracias


Código HTML:
Ver original
  1. <form action="factures.php" method="post" name="comandes2">
  2.   <input name="enviar2" type="submit" value="Mostrar" />
  3. </form>



Código PHP:
Ver original
  1. <?
  2.  
  3. if(isset($_POST['enviar2'])) {
  4. mysql_connect('localhost','root','26121994')or die ('Ha fallado la conexi�n: '.mysql_error());
  5. mysql_select_db('Clients')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
  6. $comanda = mysql_query("SELECT usuari_compres, article, quantitat, preu, pagament, UNIX_TIMESTAMP(datainicial) AS datainicial2, DATEDIFF( 'dd', CURDATE( ), datainicial2 ) AS diferencia FROM compres WHERE pagament = 'si' And diferencia BETWEEN 1 and 30");
  7. $comanda2 = mysql_num_rows($comanda);
  8.             if ($comanda2>0) {
  9.         $sql3 = mysql_query("SELECT usuari_compres, article, quantitat, preu, pagament, UNIX_TIMESTAMP(datainicial) AS datainicial2, DATEDIFF( 'dd', CURDATE( ), datainicial2 ) AS diferencia FROM compres WHERE pagament = 'si' And diferencia BETWEEN 1 and 30");
  10.             }
  11.             else{
  12.                 echo "No hi ha comandes  de ser enviades";
  13.             }
  14.  
  15. ?>
  16.  
  17.  
  18. <table width="323" height="260" border="2">
  19.   <tr>
  20.     <td>Usuari</td>
  21.     <td>Article</td>
  22.     <td>Quantitat</td>
  23.     <td>Preu</td>
  24.     <td>Pagament</td>
  25.     <td>Data de la comanda</td>
  26.     <td>Diferencia</td>
  27.     </tr>
  28.  <?php while ($imp2 = mysql_fetch_array($sql3)){?>
  29.     <tr>
  30.     <td><?php echo ''.$imp2['usuari_compres'].'';?></td>
  31.     <td><?php echo ''.$imp2['article'].'';?></td>
  32.     <td><?php echo ''.$imp2['quantitat'].'';?></td>
  33.     <td><?php echo ''.$imp2['preu'].'';?></td>
  34.     <td><?php echo ''.$imp2['pagament'].'';?></td>
  35.     <td><?php echo ''.$imp2['datainicial2'].'';?></td>
  36.     <td><?php echo ''.$imp2['diferencia'].'';?></td>
  37.      <?php } }?></tr>
  38.   </table>

Etiquetas: fecha, mysql, registro, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:38.