There is a table with three (reduced for convenience) columns:
Date of opening the card.
Period of activity: "1 month", "6 months" or "1 year".
Card status: "active", "inactive" or "expired".
What is the need to apply the algorithm for such refinement:
Exhibited a period of activity - for example, 1 month. As soon as it passes (the countdown starts from the date of opening the card), then in the table the status value changes to “expired”. How can this be done?
<tr> <td> <select size=2 name="activity"> <option disabled>Активность карты</option> <option value="На 1 месяц">На 1 месяц</option> <option value="На 6 месяцев">На 6 месяцев</option> <option value="На 1 год">На 1 год</option> </select> </td> </tr> In the <form> selection of activity is fulfilled.
Maybe this option to do. Each period corresponds to the number of days. I add these days to the date of the start of the card, and it is displayed in the fourth column, namely the "date of expiry of the card". Then I compare: if today the number is the same as in this column, then the status changes to “expired”.
Card add code:
<? require($_SERVER['DOCUMENT_ROOT'] . "/admin/main/header.php"); ?> <div class="add"> <center> <span><strong>Добавить карточку</strong></span> <a href="/admin/components/carts/" class="back-element">элементы</a> <? // А это форма редактирования записи if (!empty($_GET["id"])) { $query = "SELECT * FROM carts WHERE id=" . $_GET['id'] . ""; $result = mysql_query($query); $row = mysql_fetch_array($result); } // Добавление if (isset($_POST["insert"])) { $query = "INSERT INTO carts (series,num,date_start,date_finish,status,history,activity) VALUES ('{$_POST['series']}', '{$_POST['num']}', '{$_POST['date_start']}','{$_POST['date_finish']}','{$_POST['status']}','{$_POST['history']}','{$_POST['activity']}')"; mysql_query($query); } //Корректировка if (isset($_POST["edit"])) { $query = "UPDATE carts SET series='{$_POST['series']}',num='{$_POST['num']}',date_start='{$_POST['date_start']}',date_finish='{$_POST['date_finish']}',status='{$_POST['status']}',history='{$_POST['history']}',activity='{$_POST['activity']}' WHERE id='{$_POST['id']}'"; $result = mysql_query($query); unset($row); } //Удаление if (isset($_POST["delete"])) { $query = "DELETE FROM carts WHERE id='{$_POST['id']}'"; mysql_query($query); unset($row); } echo ' <div class="form-add"> <form method="post"><table border="0"> <tr><td><select size=2 name="status"> <option disabled>Статус карты</option> <option selected value="Активно">Активно</option> <option value="Деактивированно">Деактивированно</option> <option value="Просрочено">Просрочено</option> </select></td></tr> <tr><td><select size=2 name="activity"> <option disabled>Активность карты</option> <option selected value="На 1 месяц">На 1 месяц</option> <option value="На 6 месцев">На 6 месцев</option> <option value="На 1 год">На 1 год</option> </select></td></tr> <tr><td><input type="text" size=32 name="series" placeholder="Серия" value="' . $row["series"] . '"></td></tr> <tr><td><input type="text" size=32 name="num" placeholder="Номер карты" value="' . $row["num"] . '"></td></tr> <tr><td> Открыта<input type="datetime-local" size=32 name="date_start" value="' . $row["date_start"] . '"><input type="text" size=32 value="' . $row["date_start"] . '" readonly><br> Закрыта<input type="datetime-local" size=32 name="date_finish" value="' . $row["date_finish"]. '"><input type="text" size=32 value="' . $row["date_finish"] . '" readonly></td></tr> <tr><td><textarea name="history" placeholder="История" cols=80 rows=2>' . $row["history"] . '</textarea></td></tr> <input type="hidden" name="id" value="' . $_GET["id"] . '"> <tr><td></td><td> '; if (!empty($_GET["id"])) { echo '<input type="submit" name="edit" value="Сохранить">'; echo '<input type="submit" name="delete" value="Удалить">'; } else { echo '<br><input id="button" type="submit" name="insert" value="Добавить">'; } echo "</tr></table></form></div>";?> </center> </div> <? require($_SERVER['DOCUMENT_ROOT'] . "/admin/main/footer.php"); ?>