Solved

Change month name to number --- June to 6

Posted on 2010-08-26
5
380 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Insert Data into MySQL 5 39
str_replace not working in php script 4 28
PHP: Query an Sqlite3 Datatbase return in JSON 6 49
Cpanel file manager 8 22
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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 …

776 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