Solved

How to list next 12 months

Posted on 2009-04-07
5
957 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
Comment Utility
change this;

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

to this;

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

Author Comment

by:katlees
Comment Utility
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
Comment Utility
Ooops! Sorry...typo

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

~A~
0
 
LVL 14

Expert Comment

by:shobinsun
Comment Utility
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
Comment Utility
shobinsun, why would you post the exact same solution I just provided?

~A~
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now