Solved

Change month name to number --- June to 6

Posted on 2010-08-26
5
378 Views
Last Modified: 2013-12-13
Hey guys,

the script below shows:

2009
JUNE
2010
JUNE
AUGUST

How can i get this link:
echo "<a href='?year={$row['year']}&month={$row['month']}'>{$row['month']}</a><br />"; // in case you wanted links

to go from:
http://www.runningprofiles.com/members/test.php?year=2010&month=AUGUST
to
http://www.runningprofiles.com/members/test.php?year=2010&month=8


$start = '2010-01-01'; // start of data to look at

$end = '2010-12-30'; // end of data to look at

$query = "SELECT DISTINCT YEAR(ev_dat) as year, UPPER(MONTHNAME(ev_dat)) as month FROM diary WHERE ev_dat  ORDER BY ev_dat";

$result = mysql_query($query) or die("Query failed: $query<br />Mysql error: " . mysql_error());



$current_year = '';

while($row = mysql_fetch_assoc($result)){

        // test for a change in the year

	if($current_year != $row['year']){

		echo $row['year'] . '<br />';

		$current_year = $row['year']; // remember the new year

	}

	echo "<a href='?year={$row['year']}&month={$row['month']}'>{$row['month']}</a><br />"; // in case you wanted links

	//echo "{$row['month']}<br />";

}

Open in new window

0
Comment
Question by:runnerjp2005
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Rajesh Dalmia
ID: 33530289
in place of {$row['month']}

try

{month($row['month'])}
0
 
LVL 11

Expert Comment

by:Rajesh Dalmia
ID: 33530305
or in query use

$query = "SELECT DISTINCT YEAR(ev_dat) as year, Month(ev_dat) as month FROM diary WHERE ev_dat  ORDER BY ev_dat";

and in link use

echo "<a href='?year={$row['year']}&month={$row['month']}'>{UPPER($row['month'])}</a><br />"; // in case you wanted links
      
0
 
LVL 5

Accepted Solution

by:
doyledp earned 500 total points
ID: 33530309
You might be able to use the strtotime function

echo date("m", strtotime("MAR"));
echo date("m", strtotime("MARCH"));

would both print 03
0
 

Author Comment

by:runnerjp2005
ID: 33530333
echo "<a href='?year={$row['year']}&month={date("m", strtotime("$row['month'];"))}'>{$row['month']}</a><br />";

like that?
0
 

Author Closing Comment

by:runnerjp2005
ID: 33530370
$dd = date("m", strtotime($row['month']));
      echo "{$row['month']}"; // in case you wanted links


work a treat thanks :P
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 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

15 Experts available now in Live!

Get 1:1 Help Now