创建警告功能日期[关闭]

Create Warning Function Date. I have a case,on the data table:

Id (INT) | name (VARCHAR) | date (DATE) | expiry date (DATE).

how do I display a warning: "expired less than 1 month away!"

Data example: 001 | MILK CREAM | 2012-01-01 | 2012-06-01

warning appears in the date: 2012-05-01 ("Expiration less than 1 month").

You can select the necessary data from your database like so:

SELECT `name`,`expiry date` 
  FROM `expiry` 
 WHERE `expiry date` < NOW() + INTERVAL 1 MONTH

How you will display it will depend on what coding language you are using. If you're using PHP and MySQLi, for example, something like (error checking omitted for brevity):

<?php
$DB = new mysqli( 'your_db_host','your_username','your_password','your_db_name' );
$SQL = "SELECT `name`,`expiry date` 
    FROM `expiry` 
    WHERE `expiry date` < NOW() + INTERVAL 1 MONTH";
$result = $DB->query( $SQL );
if( $result ){
    while( $expiringSoon = $result->fetch_array() ){
        list( $name,$expiry ) = $expiringSoon;
        print "$name will expire on $expiry (less than 1 month away!)";
    }
}