What I really need is to create function in php to send email when field_number 7 date is today. And I need send data for only for example lead_id 1 if lead_id 1 field_number 7 data is today. When script will be created I want to add cron job to this file, so that it each day would check current day. My mysql data looks like below:
I am not programmer, but as far as I know code must look something like this:
//authentication for database
$hostname = "localhost";
$username = "admin";
$password = "xxxxxx";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("notification",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM tbl_lead WHERE pass_expiry >= DATE(NOW() + INTERVAL 1 DAY");
//variable for email message
$emailBody = "";
$headers = 'From: Pass Validity Reminder' . "\r\n" .
'Reply-To: myemail@email.com' . "\r\n" .
'Cc: ccemail@Wemail. com' . "\r\n".
'X-Mailer: PHP/' . phpversion();
$to = "myemail@email.com";
//fetch tha data from the database
while ($row = mysql_fetch_array($result))
{
Considering the table structure in the image use below SQL statement to get all matching records
$result = mysql_query("SELECT * FROM YOURTABLENAME WHERE lead_id='1' and field_number='7' and value=CURRENT_DATE();
Updated:
$result = mysql_query("SELECT lead_id, form_id, field_number, value FROM YOURTABLENAME WHERE field_number='7' and value=CURRENT_DATE();
Above query will provide all records with field_number
7 and value
is today date
while ($row = mysql_fetch_array($result)){
if($row['lead_id']==1){
//send email to all lead_id 1
}
if($row['lead_id']==2){
//send email to all lead_id 1
}
.... Add leads to whom you have to send email
}
If you want to retrieve data based on current date then you can use this sql query
$result = mysql_query("SELECT * FROM tbl_lead WHERE pass_expiry=CURRENT_DATE()");
This query will select all the today's date data
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.