Jump to content

Recommended Posts

I'm having trouble with the date function of PHP. I'm trying to have my script recognize what day it is so that different content can be displayed automatically. I won't be able to check/update the page manually soon, so I want the script to do it for me. I simply set up a variable ($day) that takes the numerical day of the month (date("j");). I then used if statements to check the different scenarios I have layed out, and put in the different content for those scenarios. But to no avail...

[code]
    $day = date("j");
    function frontpage($day) {
          navigation();
          if ($day == 2) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Monday, July 3rd at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Plyometric jumps, Pro agility run (12x), 150 pushups, 200 abs</li>' .
                '</ul>';
          }
          if ($day == 4) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Wednesday, July 5th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Funnel run, 15 minutes of touches, leg workout, 150 pushups, 200 abs</li>' .
                '</ul>';
          }
          if ($day == 6) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Friday, July 7th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> 30/30 Fartlek run for 15 minutes</li>' .
                '</ul>';
          }
          if ($day == 9) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Monday, July 10th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Plyometric jumps, speed/accelleration (C), 150 pushups, 200 abs</li>' .
                '</ul>';
          }
          if ($day == 11) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Wednesday, July 12th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Speed/accelleration (B), leg workout, 25 minutes of touches, 150 pushups, 200 abs</li>' .
                '</ul>';
          }
          if ($day == 13) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>No practice for Friday, July 14th</strong></li>' .
                '</ul>';
          }
          if ($day == 16) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Monday, July 17th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Plyometric jumps, speed/accelleration (A), 25 minutes of touches, 150 pushups, 200 abs</li>' .
                '</ul>';
          }
          if ($day == 18) {                 
          print '<h1>Next Practice:</h1>' .
                '<ul>' .
                '  <li><strong>When:</strong> Wednesday, July 19th at 9:00 AM</li>' .
                '  <li><strong>Where:</strong> Marysville High School Track</li>' .
                '  <li><strong>What to Bring:</strong> Flats, cleats, ball, water, etc</li>' .
                '  <li><strong>Exercises:</strong> Funnel run, leg workout, 30 minutes of touches, 150 pushups, 200 abs</li>' .
                '</ul>';
          }
    }
   
    function schedule($day) {
          navigation();
          if ($day >= 25 && $day <= 1) {
          print '<h1>This week\'s schedule is as follows:</h1>' .
                '<h2>Sunday, June 25</h2>' .
                '<ul>' .
                '  <li>40/20 Fartlek for 15 minutes</li>' .
                '  <li>20 minutes of touches on the ball</li>' .
                '  <li>150 pushups, 200 abs</li>' .
                '</ul>' .
                '<h2>Monday, June 26</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At MHS fields 6:00 PM to 7:30 PM</li>' .
                '  <li>25 minute run</li>' .
                '</ul>' .
                '<h2>Tuesday, June 27</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> Open field with Delaware and Dublin Coffman at Dublin Coffman from 6:00 PM - 8:00 PM</li>' .
                '  <li>Meet at the high school at 5:30 to car pool.</li>' .
                '</ul>' .
                '<h2>Wednesday, June 28</h2>' .
                '<ul>' .
                '  <li>25 minute run</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '  <li>Leg workout</li>' .
                '</ul>' .
                '<h2>Thursday, June 29</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At MHS fields 6:00 PM to 7:30 PM</li>' .
                '  <li>Funnel Run</li>' .
                '  <li>Pro Agility (12x)</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>' .
                '<h2>Friday, June 30</h2>' .
                '<ul>' .
                '  <li>25 minute run</li>' .
                '  <li>Plyometric jumps</li>' .
                '</ul>' .
                '<h2>Saturday, July 1</h2>' .
                '<ul>' .
                '  <li>2 mile run (timed)</li>' .
                '  <li>Email results of run to Kirsch: <a href="mailto:mksoccer4@yahoo.com">mksoccer4@yahoo.com</a></li>' .
                '  <li>Practice with a friend</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>';
          }
          if ($day >= 2 && $day <= 8) {
          print '<h1>This week\'s schedule is as follows:</h1>' .
                '<h2>Sunday, July 2</h2>' .
                '<ul>' .
                '  <li>Run for 30 minutes</li>' .
                '  <li>20 minutes of touches on the ball</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>' .
                '<h2>Monday, July 3</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At MHS fields 6:00 PM to 7:30 PM</li>' .
                '  <li>Plyometric Jumps</li>' .
                '  <li>Pro Agility Run (12x)</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>' .
                '<h2>Tuesday, July 4</h2>' .
                '<ul>' .
                '  <li>Off. Go do something!</li>' .
                '</ul>' .
                '<h2>Wednesday, July 5</h2>' .
                '<ul>' .
                '  <li>Funnel Run</li>' .
                '  <li>15 minutes of touches on the ball</li>' .
                '  <li>Leg workout</li>' .
                '  <li>150 pushups, 200 abs</li>' .
                '</ul>' .
                '<h2>Thursday, July 7</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At Delaware. Meet at 5:30 PM at MHS to carpool</li>' .
                '  <li>Performance Run</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>' .
                '<h2>Friday, July 8</h2>' .
                '<ul>' .
                '  <li>30/30 Fartlek run for 15 minutes</li>' .
                '</ul>' .
                '<h2>Saturday, July 1</h2>' .
                '<ul>' .
                '  <li>2 mile run (timed)</li>' .
                '  <li>Email results of run to Kirsch: <a href="mailto:mksoccer4@yahoo.com">mksoccer4@yahoo.com</a></li>' .
                '  <li>Practice with a friend</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>';
          }
          if ($day >= 9 && $day <= 15) {
          print '<h1>This week\'s schedule is as follows:</h1>' .
                '<h2>Sunday, July 9</h2>' .
                '<ul>' .
                '  <li>Run for 30 minutes</li>' .
                '  <li>25 minutes of touches on the ball</li>' .
                '  <li>150 pushups, 200 abs</li>' .
                '</ul>' .
                '<h2>Monday, July 10</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At MHS fields from 6:00 PM to 7:30 PM</li>' .
                '  <li>Plyometric Jumps</li>' .
                '  <li>Speed/Accelleration (C)</li>' .
                '  <li>150 pushups, 200 abs</li>' .
                '</ul>' .
                '<h2>Tuesday, July 11</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> With Delaware and Dublin Coffman, at MHS fields from 6:00 PM to 8:00 PM</li>' .
                '</ul>' .
                '<h2>Wednesday, July 12</h2>' .
                '<ul>' .
                '  <li>Speed/Accelleration (B)</li>' .
                '  <li>25 minutes of touches on the ball</li>' .
                '  <li>Leg workout</li>' .
                '  <li>150 pushups, 200 abs</li>' .
                '</ul>' .
                '<h2>Thursday, July 13</h2>' .
                '<ul>' .
                '  <li><strong>Open Fields:</strong> At MHS fields from 6:00 PM to 7:30 PM</li>' .
                '  <li>Plyometric jumps</li>' .
                '  <li>150 pushups, 150 abs</li>' .
                '</ul>' .
                '<h2>Friday, July 14</h2>' .
                '<ul>' .
                '  <li><strong>Varsity Camp (invite only): </strong>Meet at MHS from 6:00 PM to 8:00 PM. <font color="#CC0000"><strong>($25 fee)</strong></font></li>' .
                '</ul>' .
                '<h2>Saturday, July 15</h2>' .
                '<ul>' .
                '  <li><strong>Varsity Camp (invite only): </strong>Meet at MHS from 6:00 PM to 8:00 PM</li>' .
                '</ul>';
          }
    }
[/code[

Please help! ???
Thanks all.  :)

[/code]
Link to comment
https://forums.phpfreaks.com/topic/13428-problems-with-the-date-function/
Share on other sites

Depending on the page...

[quote]Warning: Missing argument 1 for frontpage() in /home/nick/public_html/practice/content.php on line 37

*  Line 37:      function frontpage($day) {[/quote]


[quote]Warning: Missing argument 1 for schedule() in /home/nick/public_html/practice/content.php on line 110

*  Line 110:      function schedule($day) {[/quote]



For one, the variable isn't being passed through the function. For two, the if statements aren't working properly to make the decision as to which statement is true.
Ok here we go i teasted a situation that your kind of in the fuction in test.php will not declair its values a result of the function set in test_result.

in test the function hello($d) goes dead due to having an extra function in place.

what the way to solve this in your code.
ansaw:
the only way i have come up with was to get rid of a function and keep one.






test_result.php
<?php

$d=date("d:m:y");

function hello($d) {


echo $d;

}



?>


test.php

<?php
include("test_result.php");

$date=date(":y");

function h($date) {


echo $d;

}

h($date);
hello($d)
?>
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.