Jump to content

[SOLVED] MONTHNAME


phpSensei

Recommended Posts

Never used this before, but any help is appreciated.

 

I am trying to get the month name from a date without using the date() function, but rather directly sql query

 

$months = mysql_query("SELECT MONTHNAME(`date`) as month FROM article ORDER BY `date` DESC") or die(mysql_error());

   while($row = mysql_fetch_array($months)){
   
   $row[month].'<br>';

      }

 

Number of Rows in Table: 3

Outputs Nothing

date form in table: 1206661977

 

 

thing is, I am using this form 1206661977, a UNIX TIMESTAMP, dont know if thats the problem.

Link to comment
https://forums.phpfreaks.com/topic/99586-solved-monthname/
Share on other sites

The results are fine, and I tried to do this the long way, by getting all the dates in timestamp, converting them to YYYY-MM-DD, and grabbing the month, and still nothing

 

<?php

  $post = mysql_query("SELECT * FROM article group by  YEAR(`date`)") or die(mysql_error());
   while($row = mysql_fetch_array($post)){
   
    // Timestamp to YYYY-MM-DD
$dates = date('Y-m-d',$row['date']);
echo $dates . '<br>';   

    // Grab Months
	$months = mysql_query("SELECT MONTH(`date`) as `months` FROM article WHERE `date` = '".$dates."'");
        while($row = mysql_fetch_array($months)){

	  echo $row['months'] . '<br>';  
	   
	 }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509487
Share on other sites

Oh fixed it, nevermind

 

TOPIC SOLVED!

How?

 

I used FROM_UNIXTIME, to convert the timestamp to a full valid date and grabbed the data with MONTHNAME or MONTH (number)

 

 

<?php 
            

$post = mysql_query("SELECT * FROM article group by YEAR(FROM_UNIXTIME(`date`)) DESC ") or die(mysql_error()); 
            
		while($row = mysql_fetch_array($post)){ // Timestamp to YYYY-MM-DD 
                                       
               $Year= date('Y',$row['date']); 
            
                echo $Year;

            // Grab Months </p>
           $months = mysql_query("SELECT * FROM article WHERE YEAR(FROM_UNIXTIME(`date`))= '".$Year."' group by MONTH         (FROM_UNIXTIME(`date`)) DESC "); 

            while($row = mysql_fetch_array($months)){ 
            echo '     <span class="arch2"><a href="javascript: toggleLayer(\'month_'.date('m',$row['date']).'_'.date('y',$row['date']).'\');">'.date('F',$row['date']). '</a></span><br>';
            
		$month_number = date('m',$row['date']); 
		$year_number = date('Y',$row['date']);


  }
		  ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-513338
Share on other sites

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.