sql >> Base de Datos >  >> RDS >> Mysql

¿Hacer eco de mysql en una tabla html?

Necesitas más o menos algo como esto:

    <?php include 'config.php';
     $data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date FROM supplier_stats") 
     or die(mysql_error()); 

     echo "<table class=\"table\" style=\"width:900px;  font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
     font-size:11px; color:#96969;\" >";

     while($row = mysql_fetch_array( $data )) { 
       $days = $row['expire_date'] -1;

       echo "<tr><td><p>".$row['id'] . "</p></td>"; 
       echo "<td><p>".$row['company_name'] . "</p></td>"; 

       if ($days > 0) {
            echo "<td><p>Insurance expires in <font color=\"red\">{$row['expire_date']} day(s)!</font></p></td>"; 
        } else {
          $when = $days*-1;           

          echo "<td><p>Insurance expires";

          if ($when > 1){
              echo " in {$when} days</p></td>";
          }

          if ($when >= 8){
            echo " <div class=\"green_light\"></div>";
          }

          if ($when <= 7){
            echo " <div class=\"red_light\"></div>";
          } elseif ($when ===1) {
            echo " tomorrow</p></td>";
          } elseif ($when == 0) {
            echo " today</p></td>";
          }
        }

        echo "<tr>";
      }

      echo "</table>"; //Close the table in HTML
    ?>