newphpcoder Posted April 27, 2012 Share Posted April 27, 2012 Hi..I need help in getting the 3 Months Name from my table field FromMonth and ToMonth.Here is the scenario.First, I select FromMonth and ToMonth.Ex.FromMonth = 5ToMonth = 7So it meansFromMonth is MayToMonth is July.Now I save the MonthNumber to my database:table- so_monthFromMonth = 5ToMonth = 7Now I need to get the between Months Name from FromMonth to ToMonth which are (May, June, July).How does it possible?Thank you so much. Link to comment Share on other sites More sharing options...
Err Posted April 27, 2012 Share Posted April 27, 2012 (edited) Use arrays: $mths = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October' 11 => 'November', 12 => 'December'); $fromMonth = 5;$toMonth = 7; // After you set the array, then just add 1 to $fromMonth every time by counting up until it reaches $toMonth,// you can do this by using a while loop.// While it's counting up, it's referencing the current number in the array which also echos out the month name. while ($fromMonth <= $toMonth) { echo $mths[$fromMonth]."<br />"; $fromMonth++;} The above should work (I didn't test). Edited April 27, 2012 by Err Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now