PDA

View Full Version : HELP -- IF/ELSE HELP



41media
January 18th, 2005, 12:05 PM
I'm a newbie to PHP. I'm working on a site for a client that involves something similiar to the Market Opens/Market Closes on www.thesubway.com. Because I'm better at PHP, I'm doing all the programming in PHP and not ASP (which is what thesubway.com is based on).

I have listed the code below. The "market closes" thing works, but when I try to display "market opens", it still says "market closes" and lists different hours and minutes.

If anyone can help, I would be greatly appreicative:

<?php

# --- Begin Market Closes In ... --- #
$mktclosetime = mktime(13,00,0,12,31,2005);
# ^-- Change Hour ("13") Accordingly for Time Zone --^ #
# ^-- Change Date ("2005") Accordingly for Current Year --^ #
$diff = $mktclosetime - time();
$days = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($days * 86400);
$hours = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($hours * 3600);
$minutes = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($minutes * 60);
$seconds = ($diff - ($diff % 1)) / 1;
# --- End Market Closes In ... --- #
# --- Begin Market Opens In ... --- #
$mktopentime = mktime(9,00,0,12,31,2005);
# ^-- Change Hour ("13") Accordingly for Time Zone --^ #
# ^-- Change Date ("2005") Accordingly for Current Year --^ #
$diff1 = $mktopentime - time();
$days1 = ($diff1 - ($diff1 % 86400)) / 86400;
$diff1 = $diff1 - ($days1 * 86400);
$hours1 = ($diff1 - ($diff1 % 3600)) / 3600;
$diff1 = $diff1 - ($hours1 * 3600);
$minutes1 = ($diff1 - ($diff1 % 60)) / 60;
$diff1 = $diff1 - ($minutes1 * 60);
$seconds1 = ($diff1 - ($diff1 % 1)) / 1;
# --- End Market Opens In ... --- #
$msg = ("System Test");
if (time() < $mktclosetime) { $msg = "Market closes in $hours:$minutes."; }
if (time() > $mktclosetime) { $msg = "Market opens in $hours1:$minutes1."; }
echo ("$msg")
?>

Thanks Again

Hans Kilian
January 18th, 2005, 12:27 PM
At the end of your script you compare the current time to 2005-12-31. That means that you wont get the 'Market opens...' message until 2006.

41media
January 18th, 2005, 12:36 PM
At the end of your script you compare the current time to 2005-12-31. That means that you wont get the 'Market opens...' message until 2006.

Got any recommendations how to fix this?

Hans Kilian
January 18th, 2005, 07:47 PM
You need to change mktopentime and mktclosetime to the timestamps when the market actually opens and closes. Like for january 19th:
$mktopentime = mktime(9,00,0,1,19,2005);
$mktclosetime = mktime(13,00,0,1,19,2005);

Of course you need to make this dynamic so you don't have to change your code every day.