Decade Range based on Year |
[eluser]weetstraw[/eluser]
Right now, I'm using a rather manual approach to defining the date range of decade based on the given year. Does anyone know a smarter solution? Code: function awards()
[eluser]Ben Edmunds[/eluser]
You can use mktime() and date(). You should be able to find everything you need here: http://php.net/manual/en/function.date.php If your still not sure after reading those let me know and I'll give you some code to go off of.
[eluser]jedd[/eluser]
If $year is always four digits, you could just substr the first 3, and append a 0 to get $min and a 9 to get $max.
[eluser]sophistry[/eluser]
Code: $min=$year[0].$year[1].$year[2].'0'; OR as jedd suggested: Code: $yr3=substr($year,0,3);
[eluser]jedd[/eluser]
In the interests of total boredom over here (plus some exasperation as I try to get my head around jquery ui - and am failing dismally) here's some thoughts. My re-interpretation of your code: Code: function awards ( $year = '9999' ) Assumptions I don't like : The year you're getting as the first parameter of your controller method is sane - it isn't necessarily going to be. Hopefully your model method sensibly checks sanity, and/or escapes the input data. I'm a big fan of is_numeric(). Where you do your data validity checks is a matter of debate - I'm happy to do some in the controller - so I'd probably do the numeric & 4-character strlen tests here. When you call : $this->Project_model->awardsList($year) -- you're assuming that if the year is current, you'll get results. Hopefully you're handling a lack of results elegantly in your view, but you might want to handle them better in here - just setting the year back to 2009 and then calling that same model method again later seems .. inelegant. Notes: Min/max creation - could also be done in three lines this way: Code: $min = $max = $year; I suspect performance deltas on any of the options presented are trivial .. but they're all less ugly (and more versatile) than the switch() approach |
Welcome Guest, Not a member yet? Register Sign In |