Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/219566-how-to-set-such-script-in/
Share on other sites

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 } ?>

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

 

 

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;
}
?>

Hi,

 

Sorry for late reply and misunderstanding, Yupe, when i tested it in localhost, it works just great :D

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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.