FifeBirder Posted November 7, 2010 Share Posted November 7, 2010 Hi Guys I have created a function, well i think i have function datedropdown_funct() { switch ($date_filter) { case "Today": $retval = '<option value="">Select</option><option value="Today" SELECTED>Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last 48hrs": $day = date("d")-1; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs" SELECTED>Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option>'; break; case "Last week": $day = date("d")-7; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week" SELECTED>Last Week</option><option value="last month">Last Month</option>'; break; case "last month": $month = date("m")-1; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month" SELECTED>Last Month</option>'; break; case "last 3 months": $month = date("m")-3; $retval = '<option value="">Select</option><option value="Today">Today</option><option value="Last 48hrs">Last 48hrs</option><option value="Last week">Last Week</option><option value="last month">Last Month</option><option value="last 3 months" SELECTED>Last 3 Month</option>'; break; default: // Default is the last 48hrs $day = date("d")-1; } return $retval; } it gets called like so $date_filter_options= datedropdown_funct(); The variable $date_filter_options should take on the $retval value, but it doesnt appear to be calling the function Any ideas or correction where i have screwed up ? regards Quote Link to comment https://forums.phpfreaks.com/topic/218048-function-issue/ Share on other sites More sharing options...
mikosiko Posted November 7, 2010 Share Posted November 7, 2010 how the function "knows" about $date_filter ? Quote Link to comment https://forums.phpfreaks.com/topic/218048-function-issue/#findComment-1131540 Share on other sites More sharing options...
FifeBirder Posted November 7, 2010 Author Share Posted November 7, 2010 Cheers my friend. Sorted Quote Link to comment https://forums.phpfreaks.com/topic/218048-function-issue/#findComment-1131542 Share on other sites More sharing options...
Anti-Moronic Posted November 7, 2010 Share Posted November 7, 2010 Yeh you need to pass in that variable and any other non-global variables. Also, I should add that what you return is very important when dealing with functions. You are not return $month or $day etc which means you cannot access them outside of that function properly. Ideally, because this is part of your other sql queries, it would be best to do a class, and then bundle a few functions together. That way you can easily manage variables between functions (or methods) by using it as an object. class mynewclass{ function datedropdown_funct(){ $this->retval = 'Im retval!'; $this->saysomething_funct(); } function saysomething_funct(){ echo $this->retval; } } // USE $class = mynewclass(); $class->datedropdown_funct(); You should be able to see the power there. This single class can very effectively manage all your needs for that page in the other thread. Finally, if you ever find yourself repeating lots of stuff an awful lot, you should probably try to reduce to something abstract. In this piece, it would be the $retval html code. Quote Link to comment https://forums.phpfreaks.com/topic/218048-function-issue/#findComment-1131550 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.