код завершения

  • Автор темы optimis
  • 20
  • Обновлено
  • 18, May 2024
  • #1
Может кто-нибудь подсказать мне, почему это не работает. Это код, сообщающий об истечении срока действия контракта. ====================================================================== следующий код: ---------------------------------------
 <?php

error_reporting(E_ALL);

// show all errors - server configured at 6135, increases to 6143 (PHP version 5.2.11) --

// comment this line out when LIVE

ini_set('display_errors','On');

// turn on error display -- comment this line out when LIVE

$contract_expiration = '2020-12-31'; // set expiration date in YYYY-MM-DD format

$days_remaining = round( (( strtotime($contract_expiration) - strtotime(date('Y-m-d')) ) / (60*60*24)) );

// computes days remaining -- (60s*60m*24h) represents 1 day

if ($days_remaining < 31) {

$contract_expiration_formatted = date('n/j/y',strtotime($contract_expiration));

// formats expiration date as M/D/YY

if ($days_remaining == 7) $GLOBALS['contract_status'] = 'expires in a week!';

// alert message for contracts expiring today

elseif ($days_remaining == 1) $GLOBALS['contract_status'] = 'expires tomorrow!';

// alert message for contracts expiring tomorrow

else $GLOBALS['contract_status'] = 'expires in '.$days_remaining.' days - on '.$contract_expiration_formatted;

// alert message for contracts expiring in 2-30 days

}

else $GLOBALS['contract_status'] = 'is current'; // contract period is beyond 30 days

// ============================= blows up here ==================================

if (date('Y-m-d') > $contract_expiration) {

if today's date is greater than your expiration date

header("location:expired-page.html");

echo "We're sorry but your contract has expired. Contact us immediately at [EMAIL][email protected][/EMAIL] ";

// a status alert message or you can populate with a web document

exit; // kills the script and prevents the parser from rendering your web application below

}

else { ?>

<HTML>

<HEAD>

</head>

<body>

<iframe src="nav.html" width="100%" height="30"

style="height:1.8em scrolling="no"

marginwidth="0" marginheight="0" border: none;>

</iframe>

<br>

<iframe src="info.html" width="100%" height="60"

style="height:1.8em scrolling="no"

marginwidth="0" marginheight="0" border: none;>

</iframe>

<?=$GLOBALS['expiration_status'];?>

</html>

<?php } ?>

==========================================

result follows:

---------------------

$contract_expiration) { if today's date is greater than your expiration date header

("location:expired-page.html"); echo "We're sorry but your contract has expired.

// a status alert message or you can

populate with a web document exit; // kills the script and prevents the parser from

rendering your web application below } else { ?>
Код (php):

optimis


Рег
03 Jul, 2011

Тем
1

Постов
3

Баллов
13
  • 03, Jun 2024
  • #2
В вашем запросе if вы сравниваете срок действия с самим собой, что не имеет смысла.

Я ожидаю, что у вас будет переменная с именем $now, которая является объектом даты.

Однако несколько десятилетий назад мой коллега вдалбливал мне в голову, что лучше всего позволить базе данных делать то, что делают базы данных.

Вот запрос, который я только что выполнил в одной из своих систем

 SELECT

`calldate`,

COUNT(`id`),

DATEDIFF(NOW(), `calldate`) AS `diff`
FROM

`calls`

GROUP BY `calldate`
ORDER BY `calldate` DESC
Код (SQL): когда я запускаю его, я получаю это Итак, в вашем скрипте вам просто нужно посмотреть на значение $row['diff'] вместо того, чтобы манипулировать переменными даты.
 

Kivalk


Рег
01 Jan, 2011

Тем
1

Постов
3

Баллов
13
  • 10, Jun 2024
  • #3
Привет, все еще шарю. У меня есть записи в базе данных с полем срока действия в формате DATE. Я хочу отображать сообщения в зависимости от срока их действия. пожалуйста, кто-нибудь, проверьте мой код. Спасибо.
 <?php

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "homedb";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error)

{ die("Connection failed: " . $conn->connect_error); }

$id=$row['id'];

$password=$row['password'];

$expiredate=$row['expiredate'];

while($row=mysql_fetch_array($result))

{

if(expiredate == expiredate - 7)

echo "<br/>1 week remaining"; }

else (expiredate == expiredate - 1)

{ echo "<br/>1 week remaining"; }

else (expiredate == today());

{ echo "<br/>we're sorry, your contract has expired"; }

?>
Код (php):
 

Djumiksc


Рег
23 May, 2012

Тем
0

Постов
3

Баллов
3
Тем
49554
Комментарии
57426
Опыт
552966

Интересно