phpSensei Posted April 4, 2008 Share Posted April 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
gluck Posted April 4, 2008 Share Posted April 4, 2008 Do print_r($months) and see what the contents are. Also use $row['month'] Quote Link to comment Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 I took out the echo, oops. Ill try thanks. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 Contents are nothing. Quote Link to comment Share on other sites More sharing options...
gluck Posted April 4, 2008 Share Posted April 4, 2008 echo the $sql on the html and run the sql on the prompt. What do you get as results on the prompt when you run the query. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 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>'; } } ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 Oh fixed it, NVM TOPIC SOLVED! Quote Link to comment Share on other sites More sharing options...
gluck Posted April 4, 2008 Share Posted April 4, 2008 Great Quote Link to comment Share on other sites More sharing options...
fenway Posted April 4, 2008 Share Posted April 4, 2008 Oh fixed it, nevermind TOPIC SOLVED! How? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted April 9, 2008 Author Share Posted April 9, 2008 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']); } ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted April 9, 2008 Share Posted April 9, 2008 Thanks... much appreciated. Quote Link to comment 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.