Jump to content

converting month number to word month


Recommended Posts

Trying to get the below to generate the month in word form from a numeric entry in a database.

elseif($_GET['rma']=="calander"){
$sql101010="SELECT DISTINCT rma_year_issued FROM $tbl_name4 ORDER BY rma_year_issued";
$result101010=mysql_query($sql101010);
while($row101010=mysql_fetch_array($result101010)){
extract($row101010);
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'">'.$rma_year_issued.'</a>
<br />';
}

if(isset($_GET['year'])){
$logout.=' | <a href="./acp_admincp.php?rma=calander">Back to RMA Calander</a>';
$rma_year_issued=$_GET['year'];
$sql111010="SELECT DISTINCT rma_month_issued FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' ORDER BY rma_month_issued";
$result111010=mysql_query($sql111010);
while($row111010=mysql_fetch_array($result111010)){
extract($row111010);
$months = array('Janurary', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
for($i=0; $i <=11; $i++){
if($rma_month_issued=$i){
$rma_month_issued2=$months[$i];
}
}
$content="";
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'">'.$rma_month_issued2.'</a>
<br />';

}
}
}

 

Basically in the data base I may have 2,5,7 under the year 2011.

 

I want to get the numeric months into words for use in the text of the link.

 

The above is returning December even though the entry in the database is 5.

Link to comment
https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/
Share on other sites

it allows you to do things like formatting the date how you want inside the query so you don't have to worry about doing it in the PHP. It also makes date based math much easier to process. Among many other things. For your example, had you used a date or datetime column type, you could have just used the date function format_date (i believe thats the name, don't quote me on it)

Alright... I converted it to date column in my table... Now I have a rma_date_issued column... Really have no idea where to go from here.

 

 

I have this right now:

elseif($_GET['rma']=="calander"){
$sql101010="SELECT DISTINCT rma_date_issued FROM $tbl_name4 ORDER BY rma_date_issued";
$result101010=mysql_query($sql101010);
while($row101010=mysql_fetch_array($result101010)){
extract($row101010);
$date_issued=date_create($rma_date_issued);
$rma_year_issued=date_format($date_issued, 'Y');
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'">'.$rma_year_issued.'</a>
<br />';
}
if(isset($_GET['year'])){
$logout.=' | <a href="./acp_admincp.php?rma=calander">Back to RMA Calander</a>';
$rma_year_issued=$_GET['year'];
$content="";
$content.=$rma_year_issued;
}
}

 

What should I do to create the page that lists the months?

elseif($_GET['rma']=="calander"){
$sql101010="SELECT EXTRACT(YEAR FROM rma_date_issued) FROM $tbl_name4 ORDER BY rma_date_issued";
$result101010=mysql_query($sql101010);
while($row101010=mysql_fetch_array($result101010)){
extract($row101010);
$rma_year_issued=$rma_date_issued;
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'">'.$rma_year_issued.'</a>
<br />';
}
if(isset($_GET['year'])){
$logout.=' | <a href="./acp_admincp.php?rma=calander">Back to RMA Calander</a>';
$rma_year_issued=$_GET['year'];
$content="";
$content.=$rma_year_issued;
}
}

 

Now returns a blank page.

elseif($_GET['rma']=="calander"){
$sql101010="SELECT DISTINCT rma_year_issued FROM $tbl_name4 ORDER BY rma_year_issued";
$result101010=mysql_query($sql101010);
while($row101010=mysql_fetch_array($result101010)){
extract($row101010);
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'">'.$rma_year_issued.'</a>
<br />';
}

if(isset($_GET['year'])){
$content="";
$logout.=' | <a href="./acp_admincp.php?rma=calander">Back to RMA Calander</a>';
$rma_year_issued=$_GET['year'];
$sql111010="SELECT DISTINCT rma_month_issued FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' ORDER BY rma_month_issued";
$result111010=mysql_query($sql111010);
while($row111010=mysql_fetch_array($result111010)){
extract($row111010);
if($rma_month_issued=="1"){$rma_month_issued2="January";}
if($rma_month_issued=="2"){$rma_month_issued2="February";}
if($rma_month_issued=="3"){$rma_month_issued2="March";}
if($rma_month_issued=="4"){$rma_month_issued2="April";}
if($rma_month_issued=="5"){$rma_month_issued2="May";}
if($rma_month_issued=="6"){$rma_month_issued2="June";}
if($rma_month_issued=="7"){$rma_month_issued2="July";}
if($rma_month_issued=="8"){$rma_month_issued2="August";}
if($rma_month_issued=="9"){$rma_month_issued2="September";}
if($rma_month_issued=="10"){$rma_month_issued2="October";}
if($rma_month_issued=="11"){$rma_month_issued2="November";}
if($rma_month_issued=="12"){$rma_month_issued2="December";}
$content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'">'.$rma_month_issued2.'</a>
<br />';
}
}
}

Back to the code in the first post in this thread. Don't define your $months array inside your loop. Put it before the start of the while(){} loop.

 

You can get the month name by simply referencing: $months[$rma_month_issued - 1]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.