HDFilmMaker2112 Posted May 30, 2011 Share Posted May 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/ Share on other sites More sharing options...
dadamssg87 Posted May 30, 2011 Share Posted May 30, 2011 $month_name = date( 'F', mktime(0, 0, 0, $month_number) ); Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222551 Share on other sites More sharing options...
Pikachu2000 Posted May 30, 2011 Share Posted May 30, 2011 You should really store dates in a field with DATE or DATETIME data type. It makes things like this so much easier to do. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222564 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 30, 2011 Author Share Posted May 30, 2011 You should really store dates in a field with DATE or DATETIME data type. It makes things like this so much easier to do. Curious to know how that would make it easier? Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222578 Share on other sites More sharing options...
mikesta707 Posted May 30, 2011 Share Posted May 30, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222580 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 30, 2011 Author Share Posted May 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222594 Share on other sites More sharing options...
mikesta707 Posted May 30, 2011 Share Posted May 30, 2011 jesus, your variable names are ridiculous. but yeah, look into the DATE_FORMAT() mysql function. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222600 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 30, 2011 Author Share Posted May 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222603 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2011 Share Posted May 30, 2011 In addition to the mysql DATE_FORMAT() function, look into the mysql MONTHNAME() function. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222608 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 30, 2011 Author Share Posted May 30, 2011 To be honest... all of this is over my head... so I'm never going to make this work on my own. Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222611 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 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 />'; } } } Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222649 Share on other sites More sharing options...
PFMaBiSmAd Posted May 31, 2011 Share Posted May 31, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/237910-converting-month-number-to-word-month/#findComment-1222653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.