TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-14-2009, 09:46 AM   #1 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default 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);
    }
}


?> 
sandhyagupta is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Font color for key based on modif date ? Peuplarchie General 1 04-14-2009 01:37 PM
Two Different Ways to Format the Time CMellor Tips & Tricks 0 09-24-2007 11:12 PM
Script Execution Time Class Wildhoney Script Giveaway 2 09-14-2007 11:36 PM
Calculating the Execution Time Wildhoney Tips & Tricks 0 09-14-2007 11:14 PM


All times are GMT. The time now is 05:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design