Solved

How to list next 12 months

Posted on 2009-04-07
5
963 Views
Last Modified: 2013-12-13
I had someone write up this code for me. It works great except for when it displays the second line of the next twelve months, it starts that line with a |
So it looks like
May 09 | Jun 09 | Jul 09 | Aug 09 | Sep 09 | Oct 09
| Nov 09 | Dec 09 | Jan 10 | Feb 10 | Mar 10 | Apr 10

How can I remove the | before the start of the second line so it looks like
May 09 | Jun 09 | Jul 09 | Aug 09 | Sep 09 | Oct 09
Nov 09 | Dec 09 | Jan 10 | Feb 10 | Mar 10 | Apr 10

<?php
	for ($i = 0; $i < 12; $i++)
								{
								$echo_date = date("M y", mktime(0, 0, 0, date("m") + $i + 1, 1, date("Y")));
	$link_date = date("mY", mktime(0, 0, 0, date("m") + $i + 1, 1, date("Y")));
	echo "<a href=\"happening.php?monthdisplay=$link_date\"><font class=\"style8\">	$echo_date</font></a>\n";
								if ($i == 5)
								{
									echo "<br />\n";
								}
								if ($i < 11)
								{
									echo " | ";
								}
	}
							?>

Open in new window

0
Comment
Question by:katlees
  • 3
5 Comments
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 24088500
change this;

if ($i < 11)
{
  echo " | ";
}

to this;

if ($i < 11 && $ != 5)
{
  echo " | ";
}
0
 

Author Comment

by:katlees
ID: 24088567
I get Parse error: syntax error, unexpected T_IS_NOT_EQUAL, expecting T_VARIABLE or '$' in /home/visitmit/public_html/happening.php on line 108

That line is
if ($i < 11 && $ != 5)
0
 
LVL 12

Accepted Solution

by:
adrian_brooks earned 500 total points
ID: 24088682
Ooops! Sorry...typo

if ($i < 11 && $i != 5)

~A~
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24088743
Hello,

Use this code:


<?php
        for ($i = 0; $i < 12; $i++)
                                                                {
                                                                $echo_date = date("M y", mktime(0, 0, 0, date("m") + $i + 1, 1, date("Y")));
        $link_date = date("mY", mktime(0, 0, 0, date("m") + $i + 1, 1, date("Y")));
        echo "<a href=\"happening.php?monthdisplay=$link_date\"><font class=\"style8\"> $echo_date</font></a>\n";
                                                                if ($i == 5)
                                                                {
                                                                        echo "<br />\n";
                                                                }
                                                                if ($i < 11 && $i!=5)
                                                                {
                                                                        echo " | ";
                                                                }
        }
                                                        ?>

Open in new window

0
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 24088820
shobinsun, why would you post the exact same solution I just provided?

~A~
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
does post require a form or curl to be post 4 55
How to obtain the string from a PHP StdObject ? 6 32
parse url to form? 7 25
Need to remove %20 from url in get 17 36
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question