Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:38+00:00 2026-05-28T01:41:38+00:00

Hi I am running the following script, the problem I am having is that

  • 0

Hi I am running the following script, the problem I am having is that the monthly functions are getting called even though it isn’t the first Monday of the month ?. What is supposed to happen is every day the every day runs, every Monday the every Monday runs, every month the monthly runs.

By the way, I havnt called these script with cron on those dates as I have to ask the server owner to setup a cron job each time which is a major pain in the rear as he takes ages to do it, so its easier to just have cron hit the script every day and I control the rest with php.

// SETS THE TIMEZONE TO UK TIME
date_default_timezone_set('Europe/London');

// DEFINES WEEKDAY AND DAY OF THE MONTH
$weekday = date('D');
$dayOfMonth = date('d');

// RUNS THE EVERY DAY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY DAY
gasoildailyemailer();
dervdailyemailer();
kerodailyemailer();
if ($weekday == 'Mon')
{

// RUNS THE WEEKLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY WEEK
 gasoilweeklyemailer();
 dervweeklyemailer();
 keroweeklyemailer();
if ($dayOfMonth <=6)

// RUNS THE MONTHLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY MONTH
gasoilmonthlyemailer();
dervmonthlyemailer();
keromonthlyemailer();
}

?>

<?php

function gasoildailyemailer() {
echo 'GAS OIL DAILY';
};
function dervdailyemailer() {
echo 'DERV DAILY';
};
function kerodailyemailer() {
echo 'KERO DAILY';
};

?>

<?php

function gasoilweeklyemailer() {
echo 'GAS OIL WEEKLY';
};
function dervweeklyemailer() {
echo 'DERV WEEKLY';
};
function keroweeklyemailer() {
echo 'KERO WEEKLY';
};

?>

<?php

function gasoilmonthlyemailer() {
echo 'GAS OIL MONTHLY';
};
function dervmonthlyemailer() {
echo 'DERV MONTHLY';
};
function keromonthlyemailer() {
echo 'KERO MONTHLY';
};

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:41:38+00:00Added an answer on May 28, 2026 at 1:41 am

    This is what you get for not always using braces:

    if ($dayOfMonth <=6) 
        gasoilmonthlyemailer();  // THIS IS INSIDE THE IF
        dervmonthlyemailer();    // BUT THIS IS OUTSIDE!
        keromonthlyemailer();    // THIS ONE TOO!
    

    Fix it by adding braces as you shoud always do (warning: possible religious argument here; this is just my own view):

    if ($dayOfMonth <=6) {
        gasoilmonthlyemailer();
        dervmonthlyemailer();
        keromonthlyemailer();
    }
    

    As an aside: you would know that only two of the three functions were being incorrectly called. Why not spell that out explicitly so that everyone else benefits from that knowledge up front?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem with the following code running on server. It works on dev
After running the following SQL statements, you will see that, MySQL has automatically created
I have Thinking Sphinx setup and working however I am having a problem getting
I can't figure out the problem in the following short script which should compare
I am running into the following problem with gzip.exe, be it from UnxUtils or
I'm running the following test Java script from the Android HttpURLConnection docs : URL
I am running the following script: RESTORE DATABASE [Name_V2] FROM DISK = N'C:\20100920_Name_V2.bak' WITH
I am trying to Run Shell script in Cygwin but I am getting Following
i'm having a problem running an integration test through Gallio. The test works fine
This problem is really puzzling to me: I have the following script working on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.