0

I am using Smarty for Template Engine.

For one page, I want to display list of months in chronological order.

The current month is July, so order should be

July
August
September
..
.
.
..
June.

Any idea ?

2
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by metalix
0

I dont know what smarty is but here is a php code:

$month = date(n);
$int[1] = 'January';
$int[2] = 'February';
$int[3] = 'March';
$int[4] = 'April';
$int[5] = 'May';
$int[6] = 'June';
$int[7] = 'July';
$int[8] = 'August';
$int[9] = 'September';
$int[10] = 'October';
$int[11] = 'November';
$int[12] = 'December';
echo $month;
$start = $month + 1;
for($i=$start;$i<=12;$i++){
echo $int[$i];
}

You could compress this if need be but should work fine
Did you want it to loop back to the start to show all 12 months?

0

You could compress this if need be but should work fine
Did you want it to loop back to the start to show all 12 months?

Ya should loop to atleast 12 months.

If this month is July, than it should go until June comes.

July
August
.......
June

Moroever, it is coming like this AugustSeptemberOctoberNovemberDecember. How can provide link to each month and seperate with br. I have no knowledge of PHP because I use only smarty template

Edited by mike_2000_17: Fixed formatting

0

Ok. I figure out the br work.

Please let me know how to get the list of upcoming 12 Months rather than limiting to current year's pending months.

1
$month = date(n);
$int[1] = 'January';
$int[2] = 'February';
$int[3] = 'March';
$int[4] = 'April';
$int[5] = 'May';
$int[6] = 'June';
$int[7] = 'July';
$int[8] = 'August';
$int[9] = 'September';
$int[10] = 'October';
$int[11] = 'November';
$int[12] = 'December';
echo $int[$month].'<br />';

if($month == 12){
$start = 1
}
else {
$start = $month + 1;
}

if($month == 1){
$finish = 12
}
else {
$finish = $month - 1;
}
for($i=$start;$i<=12;$i++){
echo $int[$i].'<br />';
}
if($finish != 12){
for($i=1;$i<=$finish;$i++){
echo $int[$i].'<br />';
}
}

Is this helpful?

Edited by metalix: error

0

It says error.

Error is coming from this line

for($i=$start;$i<=12;$i++){

But I have got the.

Below is the code.

$current = date('mY');
// Dropdown for months
$out  = "<select name=\"menu\">\n";

$isSelected = '';
for ($i = 1; $i < 13; $i++) {
  $ts = mktime(0,0,0,(date('m') + $i),0);
  $month = date('m', $ts);
  $monthname = date('F', $ts);
  $monthname1 = strtolower($monthname);
  $year  = date('Y', $ts);
  $year = ($year);
  
  $my = $month.$year;
  $isSelected = $current == $my ? 'selected="selected"' : '';
  
  $out .= "<option value=\"/month/$monthname1.php\" $isSelected>$monthname $year</option>\n";
}

$out .= "</select>\n";
echo $out;

Edited by phphit: n/a

1

If your using it in a select menu it is better to have months in correct order eg:

if month is july

<option value="<?PHP echo date(F) ?>"<?PHP echo date(F) ?></option>
<option value="">&nbsp</option>
<option value="January">January</option>
<option value="February">February</option>
etc

This will help users find dates and be less annoying

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.