TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   To write a condition based on time? (http://www.talkphp.com/absolute-beginners/4730-write-condition-based-time.html)

sandhyagupta 07-14-2009 09:46 AM

To write a condition based on time?
 
Hello,

I have written a code to send limited mails per hour. now i want to modify such that between some time(eg:11 pm to 7 am) the numbers of mails which i want to send should increase. i know i need to add an if condition. but i am not able to get what exactly and how should i put the condition.

Can anyone plz tell me.
Thanks in advance.
Here is my code:
PHP Code:

$today_date_time date("Y-m-d H:i:s");
echo
"today_date_time =$today_date_time <br>";
$today_date date("Y-m-d");
echo
"today_date=$today_date<br>";
$present_hour date("H");
echo
"present_hour=$present_hour<br>";
include 
'connect_to_databaseadmin.php';
$select_no_of_mails_in_que=mysql_query("SELECT * FROM tablename"$conn);
$no_of_mails_in_que=mysql_num_rows($select_no_of_mails_in_que);
echo 
"no_of_mails_in_que=$no_of_mails_in_que<BR>";

if(
$no_of_mails_in_que==0)
{
    exit();
}


$select_no_of_mails_sent_during_this_hour_in_tbl_countmails_cron=mysql_query("SELECT number_mails FROM countmails_cron WHERE msg_date='$today_date' AND msg_hour='$present_hour'",$conn);
while(
$number_of_mails mysql_fetch_assoc($select_no_of_mails_sent_during_this_hour_in_tbl_countmails_cron))
{
    
$no_of_mails_sent_during_this_hour=$number_of_mails[number_mails];
}
if(
$no_of_mails_sent_during_this_hour>=200)
{
    exit();
}
$no_of_mails_sent_during_this_hour_in_tbl_countmails_cron=mysql_num_rows($select_no_of_mails_sent_during_this_hour_in_tbl_countmails_cron);
if(
$no_of_mails_sent_during_this_hour_in_tbl_countmails_cron==0)
{
    
$set_tbl_countmails_cron_when_no_entry="INSERT INTO tablename(msg_date, msg_hour, number_mails) values ('$today_date', '$present_hour', 0)"
    
mysql_query($set_tbl_countmails_cron_when_no_entry$conn);
}
if(
$no_of_mails_sent_during_this_hour<200 && $no_of_mails_in_que>0)
{
    
$mailstosend=mysql_query("SELECT * FROM mailstosend_cron",$conn);
    while(
$mail_details mysql_fetch_assoc($mailstosend))
    {
        
$msg_to=$mail_details[msg_to];
        
$msg_subject=$mail_details[subject];
        
$msg=$mail_details[message];
        
$msg_header=$mail_details[header];
        echo 
"to=$msg_to<BR>";
        echo 
"subject=$msg_subject<BR>";
        echo 
"message=$msg<BR>";
        echo 
"header=$msg_header<BR>";        
    
//}
    
$insert_record_to_mailshistory="INSERT INTO tablename(msg_to, msg_subject, msg, msg_header, date_time) values ('$msg_to', '$msg_subject', '$msg', '$msg_header', '$today_date_time')"
    
mysql_query($insert_record_to_mailshistory$conn);
    
$deletemails_from_mailstosend_cron="    DELETE  FROM mailstosend_cron WHERE msg_to='$msg_to' AND subject='$msg_subject 'AND message='$msg'AND header='$msg_header'"
    
mysql_query($deletemails_from_mailstosend_cron$conn);
    
mail($msg_to$msg_subject$msg$msg_header);
    
$no_of_mails_sent_during_this_hour++;
    if (
$no_of_mails_sent_during_this_hour>200) exit;
    
$no_of_mails_in_que--;
    echo
"no_of_mails_sent_during_this_hour=$no_of_mails_sent_during_this_hour<br>";
    
$mailscountupdate="UPDATE tablename SET msg_date='$today_date', msg_hour='$present_hour', number_mails='$no_of_mails_sent_during_this_hour' WHERE (msg_date='$today_date' AND msg_hour='$present_hour')"
    
mysql_query($mailscountupdate$conn);
    }
}


?> 



All times are GMT. The time now is 06:55 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0