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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.