I've got a small side-project I'm working on, and was wondering if you guys could point me in the right direction on something I want to accomplish. I am not 100% if this is something I *SHOULD* do with PHP, or if I could accomplish it with JavaScript/jQuery instead. I don't know if I want the whole site wrapped in PHP because of this one feature, but you guys are the experts, so I'll revert to your best opinions.
I'm doing a site for a restaurant my buddy owns, and the idea I have is that I want different graphics to show on the home page, based on time of day, or day of the week. For example, if it's Monday, the graphic will be a picture of empty tables, with copy that says, "CLOSED ON MONDAYS." Similarly, if you go to the site on a Sunday, it would show an image/copy that is based around their Sunday Jazz brunches.
I was Googling around for a script or framework to control this sort of thing, but kept getting terrible search returns—I think mostly due to bad search phrases I was using, as I tended to only get countdown timers and such in my Google results.
Do any of you guys have a recommendation for something like this, or even a particular out-of-the-box script, that you could point me to?
Thanks, I really appreciate the community here!![]()
Really surprised no answer yet.
Well you can do this in pure javascript, a basic function would be on the lines of
that will output 1 because it is Monday, i don't think you need to assign them to the months except for aesthetics but...Code:<script type="text/javascript"> var date = new Date(); document.write(date.getDay()); </script>
that should output the dayCode:<script type="text/javascript"> var day=new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; document.write("Today is " + weekday[day.getDay()]); </script>
now for the image, i guess you can do it by if and else
continuing from the past code
That code works in firefoxCode:<img src="" ID="image" border="0" /> <script type="text/javascript"> var day=new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; var x = weekday[day.getDay()]; if(x == "Monday"){ document.getElementById('image').src = "monday.png"; } </script>i know there are better ways, I'm in a lazy mood sorry for crap
Dude, thanks a bunch. I'll tinker with this tomorrow, and let you know if I have any questions.
THANKS! THANKS! THANKS! THANKS! THANKS!
i still bored that's php, it makes an image with the date printed on it... it was funCode:<?php $img = imagecreatetruecolor(200,100); $black = imagecolorallocate($img, 0,0,0); $blue = imagecolorallocate($img, 46,103,173); imagefill($img,0,0, $black); $day = date("l"); imagettftext($img, 40, 0, 15, 60, $blue, "font.ttf", $day); header("content-type: image/png"); imagepng($img); imagedestroy($img); ?>
I may end up opting for Javascript, as there's really no need for me to wrap the whole site in PHP is not necessary.
Thanks a ton, I'm gonna try out the JS tomorrow, and let you know if I have any questions.
Based on the way Javascript works (client-side), I will have to use PHP in order to most accurately determine the relevant time to use. I don't want users in another time zone to see that the restaurant is closed, if in fact the restaurant is open.
So I copied out your PHP work, slapped it into a .PHP file, threw it up on my server, and got this error message:
Any thoughts on this?Code:Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/dylanm/public_html/sandy/index.php on line 9 ‰PNG IHDRÈdLäè\PIDATxœíÁ‚ ÿ¯nH@üêÄ•|—bIEND®B`‚
That PHP code is just a plain example of drawing a picture with the days name on it, it's not what you want.
you need something like this:
Please note that I can't know what you want to do on each day, so you need to fix that code lines starting with // for each weekday.Code:switch(date("l")) {
case 0: {
// do sunday stuff
break;
}
case 1: {
// do monday stuff
break;
}
// here you do the same with cases 2-6 for tuesday to saturday
}
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks