07.02.2019, 14:11. Показов 576. Ответов 1
Доброго всем дня ! ,прошу помощи до делать запрос нахождения и отправки данных с БД MYSQL на почту
Ниже код работает отлично , данные находит отправляет красивые формы !(Показано на рисунке ).
Но хочется большего например:
добавить IF( если поле в бд chsettim == 1)
{
ПЕРВЫЙ ЗАПРОС ЕСЛИ == 1 $sqlCommand = "SELECT * FROM alert WHERE kogda BETWEEN CURDATE() AND CURDATE()+INTERVAL 1 DAY AND checktip = '2'";
}
IF( если поле в бд chsettim == 2)
{
ВТОРОЙ ЗАПРОС ЕСЛИ == 2 $sqlCommand = ///////****WHERE kogda (ЧЕРЕЗ 30 МИНУТ**
}
IF( если поле в бд chsettim == 3)
{
ТРЕТИЙ ЗАПРОС ЕСЛИ == 3 $sqlCommand = ///////***WHERE kogda (ЧЕРЕЗ 12 ЧАСОВ**
}
с выборкой думаю сам справлюсь а вот IF пока не знаю как.
Пробовал типа такого:
| PHP |
1
2
3
4
5
| $sqlCommand1 = "SELECT chsettim FROM alert";
$query = mysqli_query($db, $sqlCommand1) or die (mysqli_error($db));
//$chsettims = $row['chsettim'];
if($row['chsettim'] == 3)
{ |
|
не хочет
полный код (РАБОЧИЙ)
| PHP |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| <?php
error_reporting(-1);
header('Content-Type: text/html; charset=utf-8');
$db = mysqli_connect("localhost" , "denisa8n_nb", "Z4*5552P") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"denisa8n_nb") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
} else {
/*SUCCESS MSG*/
echo '';
}
[B]ПЕРВЫЙ ЗАПРОС ЕСЛИ == 1 $sqlCommand = "SELECT * FROM alert WHERE kogda BETWEEN CURDATE() AND CURDATE()+INTERVAL 1 DAY AND checktip = '2'";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
$current_visitor=0;
//$current_email = 'setmail';
$headers = "From: 220м@domain.ru\r\n";
$subject = "Напоминание с программы 'Прием заказов 220v' ";
//fetch the data from the database
while ($row = mysqli_fetch_array($query)) {
$arr_ids[] = $row['id'];
// has visitor_id changed
if ($row['id'] != $current_visitor) {
// send email to current visitor
if ($current_visitor != 0)
{ $to = $current_email;
$sendmail = mail($to, $subject, $message, $headers);
if ($sendmail) {
echo nl2br($message);
echo "<b>Email Successfully Sent</b><br><br>";
} else {
echo "<b>Error in Sending of Email to $to</b><br><br>";
}
}
$current_visitor = $row['id'];
$current_email = $row['setmail'];
$message = $row['deistvia'];
}
$message .= ' <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width"> <title>Modular Template Patterns</title> </head> <body style="height:100% !important;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;width:100% !important;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background-color:#F5F5F5;" > <center> <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;height:100% !important;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;width:100% !important;background-color:#F5F5F5;" > <tbody><tr> <td align="center" valign="top" id="bodyCell" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;height:100% !important;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-right:0;padding-left:0;width:100% !important;padding-top:40px;padding-bottom:40px;" > <table border="0" cellpadding="0" cellspacing="0" width="600" id="emailBody" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background-color:#FFFFFF;border-width:1px;border-style:solid;border-color:#DDDDDD;border-collapse:separate;border-radius:4px;" > <tbody><tr> <td align="center" valign="top" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <table border="0" cellpadding="0" cellspacing="0" width="600" class="flexibleContainer" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" width="600" class="flexibleContainerCell" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;padding-top:20px;padding-Right:20px;padding-Left:20px;" > <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td valign="top" class="textContent" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#404040;font-family:Helvetica;font-size:16px;line-height:125%;text-align:Left;padding-bottom:20px;" > <h3 style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;color:#202020;font-family:Helvetica;font-size:20px;line-height:125%;text-align:Left;" >';
$message .= "".$row['data'] ." \nБыла оставлена заявка в программе (Прием Заказов) на имя ".$row['lnamest'] ." ";
$message .= '</h3><br>';
$message .= " Напоминаем вам что : " .$row['kogda'] ." в : " .$row['time']."\nНужно (".$row['deistvia'].")\n";
$message .= '</td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> <tr> <td align="center" valign="top" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <table border="0" cellpadding="0" cellspacing="0" width="600" class="flexibleContainer" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" width="600" class="flexibleContainerCell bottomShim" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;padding-top:20px;padding-Right:20px;padding-Left:20px;padding-bottom:20px;" > <table border="0" cellpadding="0" cellspacing="0" width="100%" class="nestedContainer" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background-color:#E5E5E5;border-width:1px;border-style:solid;border-color:#CCCCCC;" > <tbody><tr> <td valign="top" class="nestedContainerCell" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;padding-top:20px;padding-Right:20px;padding-Left:20px;" > <table align="Left" border="0" cellpadding="0" cellspacing="0" width="160" class="flexibleContainer" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" class="bottomShim" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;padding-bottom:20px;" > <table border="0" cellpadding="0" cellspacing="0" width="160" class="emailCalendar" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background-color:#FFFFFF;border-width:1px;border-style:solid;border-color:#CCCCCC;" > <tbody><tr> <td align="center" valign="top" style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td align="center" valign="top" class="emailCalendarMonth" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;background-color:#2C9AB7;color:#FFFFFF;font-family:Helvetica, Arial, sans-serif;font-size:16px;font-weight:bold;padding-top:10px;padding-bottom:10px;text-align:center;" >';
$message .= " ".$row['kogda'] ."";
$message .= '</td> </tr> <tr> <td align="center" valign="top" class="emailCalendarDay" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#2C9AB7;font-family:Helvetica, Arial, sans-serif;font-size:40px;font-weight:bold;line-height:100%;padding-top:20px;padding-bottom:20px;text-align:center;" > ';
$message .= " ".$row['time'] ."";
$message .= '</td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> <table align="Right" border="0" cellpadding="0" cellspacing="0" width="320" class="flexibleContainer" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" > <tbody><tr> <td valign="top" class="textContent" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#404040;font-family:Helvetica;font-size:16px;line-height:125%;text-align:Left;padding-bottom:20px;" > <h3 style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;color:#202020;font-family:Helvetica;font-size:20px;line-height:125%;text-align:Left;" >';
$message .= 'Информация о заметки';
$message .= '</h3> <br> ';
$message .= " ".$row['svedenia'] ."";
$message .= '</td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> <tr> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr> </tbody></table> </td> </tr></tbody></table> </td> </tr> </tbody></table> </center> </body></html>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Bcc: birthday-archive@example.com\r\n";
//mail($to, $subject, $message, $headers);
}
}[/B]
//$db->query($sql);
$db->query($sql) or die(mysqli_error($db));
// Free the results
mysqli_free_result($query);
//close the connection
mysqli_close($db);
?> |
|