Daguse Posted May 17, 2006 Share Posted May 17, 2006 [code] $query = "SELECT DISTINCT(DATE_FORMAT(post_date, '%M %Y')) FROM $tablename"; if ($result = mysql_query ($query)) { while ($row = mysql_fetch_array ($result)) { echo("Date {$row['DATE_FORMAT']} <br>"); [/code]So when I use the above code I don't get any thing from the date format just Date after each selection. Can any one inform me on why my echo is not working.... Thank you! Link to comment https://forums.phpfreaks.com/topic/9881-echoing-select-distinct-in-array/ Share on other sites More sharing options...
ryanlwh Posted May 17, 2006 Share Posted May 17, 2006 if you run this query in the mysql command line or phpmyadmin, you'll see that the column returned for this query is "DATE_FORMAT(post_date, '%M %Y')", not just "DATE_FORMAT". One tip for you is to use mysql aliases.[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] [color=green]DISTINCT[/color] DATE_FORMAT(post_date, [color=red]'%M %Y'[/color]) [color=green]AS[/color] formatted [color=green]FROM[/color] [color=orange]table[/color] [!--sql2--][/div][!--sql3--]Then, you can reference this column by $row['formatted']; If you're using fetch_array or fetch_row, you can also try $row[0] . Link to comment https://forums.phpfreaks.com/topic/9881-echoing-select-distinct-in-array/#findComment-36729 Share on other sites More sharing options...
wildteen88 Posted May 17, 2006 Share Posted May 17, 2006 Change your code to this:[code]$query = "SELECT DISTINCT(DATE_FORMAT(post_date, '%M %Y')) FROM $tablename"; if ($result = mysql_query ($query)) { while ($row = mysql_fetch_array ($result)) { echo("Date {$row['post_date']} <br>");[/code]DATE_FORMAT is not the name of the row you are getting the data from, but post_date is Link to comment https://forums.phpfreaks.com/topic/9881-echoing-select-distinct-in-array/#findComment-36730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.