firezz Posted November 23, 2010 Share Posted November 23, 2010 Hi, I have 2 files here <index.php> and <date.js> I need to do something like this : when the server day is Tuesday, i will display a set of javascript / advertisement ++++++++++++++++++++++++++++++++++++++++++++++++ index.php ------------ <script language="JavaScript" src="date.js"></script> <html> <head> </head> </html> ++++++++++++++++++++++++++++++++++++++++++++++++ date.js --------- var now = new Date(); var days = new Array( 'Sunday','Monday','Tuesday', 'Wednesday','Thursday','Friday','Saturday'); today = days[now.getDay()] ; if (today=="Tuesday") { document.write("<script language='JavaScript' src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vj?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"></script><noscript><a href="http://a.admaxserver.com/servlet/ajrotator/414071/0/cc?z=admaxasia2&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"><img src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vc?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee&abr=$imginiframe" width="300" height="250" border="0"></a></noscript>"); } else if (today=="Friday") { document.write("<b>Good Friday morning</b>"); } else { document.write("<b>Good morning</b>"); ++++++++++++++++++++++++++++++++++++++++++++++++ I just need the advertisement to show on Tuesday only and the script for advertisement <script language="JavaScript" src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vj?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"></script><noscript><a href="http://a.admaxserver.com/servlet/ajrotator/414071/0/cc?z=admaxasia2&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"><img src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vc?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee&abr=$imginiframe" width="300" height="250" border="0"></a></noscript> I have tried to use the command but it seems not working this way .. Is there any problem with the script ? or i do not need the date.js to do so ? Please advise thank you Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/ Share on other sites More sharing options...
JonnoTheDev Posted November 23, 2010 Share Posted November 23, 2010 Use PHP not Javascript. <?php $dayOfWeek = date("w"); /* if tuesday */ if($dayOfWeek == 2) { ?> <script language='JavaScript' src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vj?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"></script><noscript><a href="http://a.admaxserver.com/servlet/ajrotator/414071/0/cc?z=admaxasia2&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"><img src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vc?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee&abr=$imginiframe" width="300" height="250" border="0"></a></noscript> <?php /* if friday */ } elseif($dayOfWeek == 5) { ?> <b>Good Friday morning</b> <?php /* any other day */ } else { ?> <b>Good morning</b> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1138378 Share on other sites More sharing options...
firezz Posted November 23, 2010 Author Share Posted November 23, 2010 thanks for the reply, i have tried it, and found something unusual as well /* if tuesday */ if($dayOfWeek == 2) { ...... i tried to change it /* if tuesday */ if($dayOfWeek == 1) { It is displaying the advertisement with "Good Friday morning Good morning" So can i assume that, no matter what happen to which day, it will still display all 3 elements too ? (advertisement, Good Friday morning, Good morning) thanks Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1138383 Share on other sites More sharing options...
JonnoTheDev Posted November 23, 2010 Share Posted November 23, 2010 Simpler implementation <?php $dayOfWeek = date("w"); switch($dayOfWeek) { case 2: ?><script language='JavaScript' src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vj?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"></script><noscript><a href="http://a.admaxserver.com/servlet/ajrotator/414071/0/cc?z=admaxasia2&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"><img src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vc?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee&abr=$imginiframe" width="300" height="250" border="0"></a></noscript><?php break; case 5: print "<b>Good Friday morning</b>\n"; break; default: print "<b>Good morning</b>\n"; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1138396 Share on other sites More sharing options...
firezz Posted November 23, 2010 Author Share Posted November 23, 2010 hi thanks, but whenever i tried on the code, they are the same still pls refer to the image http://nendoroiz.com/test.jpg i changed my pc date from monday to sunday ... they are still gives me the same result... as the image there Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1138472 Share on other sites More sharing options...
JonnoTheDev Posted November 23, 2010 Share Posted November 23, 2010 It is a PHP file not a HTML document! You must save the file as .php i.e index.php You must test on a server running php or have php running on your computer. I thought you said you have an index.php file? Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1138493 Share on other sites More sharing options...
firezz Posted November 26, 2010 Author Share Posted November 26, 2010 Hi, Sorry for late reply and misunderstanding, Yupe, when i tested it in localhost, it works just great Soon after while trying to re-edit the source file, i found out it is not .php file. instead, the extension is - .tpl (main.tpl) from one of the files for punbb <forum> can that be implemented too ? i will try to test on it once i got back home (on outstation with limited internet connectivity atm) Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1139857 Share on other sites More sharing options...
JonnoTheDev Posted November 26, 2010 Share Posted November 26, 2010 What template engine does punbb use. Is it smarty? If it does just enclose the code as follows in the template file: {php} $dayOfWeek = date("w"); switch($dayOfWeek) { case 2: {/php} <script language='JavaScript' src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vj?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"></script><noscript><a href="http://a.admaxserver.com/servlet/ajrotator/414071/0/cc?z=admaxasia2&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee"><img src="http://a.admaxserver.com/servlet/ajrotator/414071/0/vc?z=admaxasia2&dim=280733&pid=7127b37b-3892-4347-8bae-3c9cccf05f6c&asid=1d4556ac-49ee-4004-a196-986327e519ee&abr=$imginiframe" width="300" height="250" border="0"></a></noscript> {php} break; case 5: print "<b>Good Friday morning</b>\n"; break; default: print "<b>Good morning</b>\n"; break; } {/php} http://www.smarty.net/docs/en/language.function.php.tpl Quote Link to comment https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/#findComment-1139863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.