Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Tue Jan 30, 2007 3:00 pm Reply with quote

I have a function that doesn't seem to be working. Maybe its the way I'm calling it.

I call the function like this.

checkresupplydate();

And the function does this based on what day of the week it is.

Code:
function checkresupplydate(){ 

include_once("header.php");
global $db, $prefix;

$curdayofweek = date('w'); // returns 0-6 with 0 == Sunday

if ($curdayofweek < 1 || $curdayofweek > 3){
Opentable();
echo "Reenforcements are only allowed from Monday till Wednesday<br>";
echo " These should be done in conjunction with Moves";
Closetable();
}
include('footer.php');
}


If it is before Sunday or after Wednesday they should not continue but have this displayed:

echo "Reenforcements are only allowed from Monday till Wednesday<br>";
echo " These should be done in conjunction with Moves";

What I am getting is just a blank page. On Tuesday I echoed out $curdayofweek and am getting 2 which is correct.

Why is this not working?
 
View user's profile Send private message Visit poster's website ICQ Number
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Tue Jan 30, 2007 3:21 pm Reply with quote

On Tuesday you should get a blank page by that logic. Is 2 < 1? No. Is 2 > 3? No. So you don't do anything. What did you expect to happen on Tuesday?

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
Donovan







PostPosted: Tue Jan 30, 2007 5:38 pm Reply with quote

So it wouldn't do anything, However contol is left in the function and not returned to the page that called the function. From page.php I call checkresupplydate() and if it is Monday, Tuesday, or Wednesday I want control returned to page.
 
technocrat
Life Cycles Becoming CPU Cycles



Joined: Jul 07, 2005
Posts: 511

PostPosted: Tue Jan 30, 2007 6:57 pm Reply with quote

Well your including the footer in that function, ad you sure you want to do that?

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! / Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Thu Feb 01, 2007 7:31 pm Reply with quote

Then you would need a return statement,
Try this on for size.
function checkresupplydate(){
include_once("header.php");
global $db, $prefix;

$curdayofweek = date('w'); // returns 0-6 with 0 == Sunday

if ($curdayofweek < 1 || $curdayofweek > 3){ //Will only return $var on sunday, thursday friday and saturday.
//Opentable(); //make this happen no matter what day in your calling page.
$var="Reenforcements are only allowed from Monday till Wednesday<br>";
$var.= " These should be done in conjunction with Moves";
//Closetable(); //make this happen no matter what day in your calling page.
}
if (!isset($var){
return false;
}else{
return $var;
}
//include('footer.php'); //make this happen no matter what day in your calling page.
}

Call it like $condition=checkresupplydate();
if ($condition!=false){
Opentable();
echo $condition;
Closetable();
}else{
//Do something on allowed days.
}
include ('footer.php');

Keeping the work of displaying out of the hands of a conditional function allows for you to not accidently include or do something twice, and its just good practice IMO.

_________________
For those who stand shall NEVER fall and those who fall shall RISE once more!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©