Jump to content


Photo

Problems with the date function


  • Please log in to reply
7 replies to this topic

#1 Nicholas

Nicholas
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationOhio, USA

Posted 02 July 2006 - 04:07 AM

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

     $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.  :)


Homicidal Psycho Jungle Cat

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 July 2006 - 04:13 AM

Whats the problam then?
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Nicholas

Nicholas
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationOhio, USA

Posted 02 July 2006 - 04:20 AM

Depending on the page...

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

*  Line 37:      function frontpage($day) {



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

*  Line 110:      function schedule($day) {




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.
Homicidal Psycho Jungle Cat

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 July 2006 - 04:40 AM

Try it with out the navagation() function present ok.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 02 July 2006 - 06:46 AM

where in your script are you actually calling these functions?


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 02 July 2006 - 09:17 AM

So when you are calling the functions you are doing this right:

<?php

$day = date("j");

frontpage( $day );
schedule( $day );

?>


#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 July 2006 - 11:28 AM

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

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 Nicholas

Nicholas
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationOhio, USA

Posted 02 July 2006 - 11:54 AM

Thanks for you're help. I won't have the chance to play with this though, so I just put up all the content for now. When I get the opportunity, I'll have to review your code to understand what you're doing. Thanks again though.
Homicidal Psycho Jungle Cat




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users