php – How to enter a counter inside the while?

Question:

If you can help me on how I could enter a counter inside the while, the idea is at the moment I filter it by a range of dates, it shows me the information, otherwise if it is on the outside, do not show me if you can help me thank you very much.

here is the code

<?php
require_once('../conexion/conexion.php');

// echo "hola";
$id_convenios =$_POST['id_convenios'];
$bus =$_POST['bus'];
$fechai =$_POST['fechai'];
$fechaf =$_POST['fechaf'];

$sql = "SELECT   ca.id_campanas,
ca.nombre,
esc.nombre estado_campanas,
co.nombre convenios,
ca.presupuesto,
ca. fc
   FROM campanas ca 
   INNER JOIN estado_campanas esc ON esc.id_estadoc = ca.id_estadoc
   INNER JOIN convenios co ON co.id_convenios = ca.id_convenios
   WHERE  ca.nombre like '%$bus%'
   AND ca.id_convenios = '$id_convenios' 
   AND ca.estado = 'Activo'
   AND date(`fecha_i`) BETWEEN date('$fechai') AND date('$fechaf')
   ";
echo "</br>";
echo $sql;
$result = mysqli_query($link, $sql);

  echo "</br>";
    echo '<table class="table table-hover">

           <a class="align-middle">
              <thead>
              <tr style="background:#e1e2e6;">
                    <th style="color: #1674ae;text-align: center;">Nombre de la Campaña</th>
                    <th style="color: #1674ae;text-align: center;">Nombre Estado de la Campaña</th>
                    <th style="color: #1674ae;text-align: center;">Nombre del Convenio</th>
                    <th style="color: #1674ae;text-align: center;">Presupuesto</th>
                    <th style="color: #1674ae;text-align: center;">Fecha de Creación</th>
                </tr>
              </thead>';    
              $filas=0;

              while ($filas = mysqli_fetch_array($result)) 
             {
                if($filas<0){    
                  echo "<tr>
                  <td style='text-align: center'>$filas[nombre] </td>
                  <td style='text-align: center'>$filas[estado_campanas]</td>
                  <td style='text-align: center'>$filas[convenios]</td>
                  <td style='text-align: center'>$filas[presupuesto]</td>
                  <td style='text-align: center'>$filas[fc]</td>
             </tr>";
             $filas++;
                } 

                else {
                  echo "no se encontraron resultados";
                }
              } 
               echo "</table> <br> </div>";
?>

Answer:

I don't know if I have understood your problem correctly, because, as someone has pointed out, your question is a bit confusing. However, two things.

The first thing, where you put if ($ rows <0). In that scenario, that condition will never be met. The number of responses to a query will be 0, or greater, but never less.

The second. Make sure the dates come to the query in the extended ISO 8601 format, or your bounding won't work. Take a look at https://es.wikipedia.org/wiki/ISO_8601 .

Scroll to Top