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. Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/ 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'] Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509467 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. Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509469 Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 Contents are nothing. Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509471 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. Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509477 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>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509487 Share on other sites More sharing options...
phpSensei Posted April 4, 2008 Author Share Posted April 4, 2008 Oh fixed it, NVM TOPIC SOLVED! Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509490 Share on other sites More sharing options...
gluck Posted April 4, 2008 Share Posted April 4, 2008 Great Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509550 Share on other sites More sharing options...
fenway Posted April 4, 2008 Share Posted April 4, 2008 Oh fixed it, nevermind TOPIC SOLVED! How? Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-509552 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']); } ?> Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-513338 Share on other sites More sharing options...
fenway Posted April 9, 2008 Share Posted April 9, 2008 Thanks... much appreciated. Link to comment https://forums.phpfreaks.com/topic/99586-solved-monthname/#findComment-513356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.