Jump to content

new message every day


grucker
 Share

Go to solution Solved by grucker,

Recommended Posts

I have had a different message appearing evry day based on the name of the day. I now want a message based on the date up to 31. I have tried messing to no no avail. Help will be appreciated

 

 

$day_post = "includes/days";
 
$today = date('l');
if (file_exists($day_post."/".$today.".php"))
    {   
    /**echo "$day_post/".$today.".php"; **/
include("$day_post/".$today.".php");
    } else {   
    echo "No thoughts came into my head $today";
}
 

Link to comment
Share on other sites

Have you already (re)named the files?

 

$today = date('l');
That's what it uses to determine the name of the file. Check the documentation to see how to make it return a day number instead of a weekday name.

 

I renamed the files 1.php 2.php etc. but the else message came up. I tried the various other letters in the code you advised but the else message still came up with the name of todays day i.e. Thursday so it doesnt seem to have changed anything. I even cleared the letter from the parentheses so it was $today = date(''); and the day name still came up. Could you give more advice please.

Link to comment
Share on other sites

Have you tried using a root-relative link? For example, you could try something like:

$day_post = "{$_SERVER['DOCUMENT_ROOT']}/includes/days";

Of course, you may need to adapt the path which comes after the SERVER variable. More information about the SERVER variable can be found here:

http://php.net/manual/en/reserved.variables.server.php

Link to comment
Share on other sites

Have you tried using a root-relative link? For example, you could try something like:

$day_post = "{$_SERVER['DOCUMENT_ROOT']}/includes/days";

Of course, you may need to adapt the path which comes after the SERVER variable. More information about the SERVER variable can be found here:

http://php.net/manual/en/reserved.variables.server.php

Dont think its that. When I called the files monday etc. and asked for the daily message everything worked fine. Renaming the fies to 1, 2 3 etc. and calling the month day number results in error message but for the day in question. So no wiser.

Link to comment
Share on other sites

the files are 1 through 31 .php

 

<?php // Change $day_images to the location of images
$day_post = "includes/days";
 
$today = date('');
if (file_exists($day_post."/".$today.".php"))
    {   
    /**echo "$day_post/".$today.".php"; **/
include("$day_post/".$today.".php");
    } else {   
    echo "No thoughts came into my head $today";
}
?>
Link to comment
Share on other sites

  • Solution

I think the issue is that you were originally passing 'l' to the date function which gives you a value from "Sunday" through "Saturday". Have you tried "j"?

$today = date('j');

That gives you the day of the month 1 to 31.

Thank you ever so much that is the answer

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.