grucker Posted November 20, 2013 Share Posted November 20, 2013 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";} Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/ Share on other sites More sharing options...
requinix Posted November 20, 2013 Share Posted November 20, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459274 Share on other sites More sharing options...
grucker Posted November 21, 2013 Author Share Posted November 21, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459330 Share on other sites More sharing options...
cyberRobot Posted November 21, 2013 Share Posted November 21, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459358 Share on other sites More sharing options...
grucker Posted November 21, 2013 Author Share Posted November 21, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459418 Share on other sites More sharing options...
requinix Posted November 21, 2013 Share Posted November 21, 2013 So what's your code now after the changes you made? Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459419 Share on other sites More sharing options...
cyberRobot Posted November 21, 2013 Share Posted November 21, 2013 So what's your code now after the changes you made? @grucker - When posting the code, please surround it with tags. It makes the code and the post easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459424 Share on other sites More sharing options...
grucker Posted November 21, 2013 Author Share Posted November 21, 2013 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459453 Share on other sites More sharing options...
cyberRobot Posted November 22, 2013 Share Posted November 22, 2013 (edited) 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. Edited November 22, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459455 Share on other sites More sharing options...
Solution grucker Posted November 24, 2013 Author Solution Share Posted November 24, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284120-new-message-every-day/#findComment-1459820 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.