alert box for expiry date

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Prensil
New php-forum User
New php-forum User
Posts: 81
Joined: Sat May 07, 2011 12:05 am

Tue Jun 21, 2011 11:35 pm

I dont have any script right now but i can give idea regarding it.

First of all create a database and insert records as per your need.
Now create cron job which will call a php file daily in the morning (or whatever time you want). This file will have a code to fetch the records from database and compare the date in the database with the current date and if it matched then alert a message. You can right the javascript code for alert message in php file.

I think this will help you.

Thanks & Regards,
Prensil Technologies Pvt. Ltd.
php web development company
http://www.prensil.com

eswari
New php-forum User
New php-forum User
Posts: 17
Joined: Mon Jun 20, 2011 3:46 am

Wed Jun 22, 2011 8:59 pm

I think this will useful to you....

Code to update the alert box
Code:
<!-- SWSP alert box update -->
<?php include_once("SWSP-config.php"); // for settings
// update SWSP alert box if needed
if($useAlertBox) { // if set to true, do the following
$SWSPtime = date("U"); // current time
$SWSPabTime = date("U",filemtime($dataFolder.'/SWSPdatacache.php')); // cache file time
if($SWSPtime - $SWSPabTime > $SWSPcacheTime) { // IF cache time expired, do the following
include("SWSP-core.php"); // update the cache file
echo "<!-- SWSPalertBox: Cache file updated. -->\n";
}
else {
echo "<!-- SWSPalertBox: Cache file has not expired. -->\n";
}
} ?>
<!-- End of SWSP alert box update -->

And the alert box code.
Code:
<!-- SWSP alert box -->
<?php include($dataFolder.'/SWSPdatacache.php'); if($SWSPalertBox !== '') {print_r($SWSPalertBox);} ?>
<!-- End of SWSP alert box -->

eswari
New php-forum User
New php-forum User
Posts: 17
Joined: Mon Jun 20, 2011 3:46 am

Thu Jun 23, 2011 9:37 pm

I hope it should be useful to you... :)

Prensil
New php-forum User
New php-forum User
Posts: 81
Joined: Sat May 07, 2011 12:05 am

Thu Jun 23, 2011 10:52 pm

ok, i'll try to make you understand.

1) First of all create a database and insert records as per your need.

I hope you will be able to create a database and a table and insert records having fields as per your requirement. And i think that there will be a field for date (expiry date).

2) This file will have a code to fetch the records from database and compare the date in the database with the current date and if it matched then alert a message. You can right the javascript code for alert message in php file.

Create a php file which will fetch records from database. Now make a foreach loop to go through the records and fetch the expiry date in the loop and compare it with the current date if it matches then echo an alert message
eg:
say php file named "cron.php"

$query = 'select * from lease';
$result = mysql_query($query);
foreach($row = mysql_fetch_array($result))
if($row['expirydate'] == $curdate)
{
echo '<script language="javascript">alert("Your lease had been expired.")</script>';
}

Check this script by executing it that this works fine or not. Once this is fine you can go for creating cronjob. Let me first make you understand what cronjob is, here is the definition "The cron daemon is a long running process that executes commands at specific dates and times.". Cronjob will execute this file(the above cron.php file)

3) Create a cronjob which will call the cron.php file daily and as it will call cron.php file daily, your code will check the database and if there is any record having lease expired then your file cron.php will display an alert message.

I hope this will help you.

Thanks & Regards,
Prensil Technologies Pvt. Ltd.
php web development company
http://www.prensil.com

clarke21
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Oct 24, 2018 4:24 am

Wed Oct 24, 2018 4:30 am

This helps you to create a alert box for expiry date.
<?php
$date_now = date_create(date('Y-m-d'));
$date_db = date_create('2018-02-10');

$date_diff = date_diff($date_now,$date_db);
echo '<pre>';
print_r($date_diff);
echo '</pre>';
?>
and the result is ..
DateInterval Object
(
[y] => 1
[m] => 4
[d] => 12
[h] => 0
=> 0
[s] => 0
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 499
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)

php development company india

php website development company

Post Reply