hi everyone

im having issues with some results i need, basically i have a view page that needs to output results based on earnings per month.
all results are collected and outputted in rows, is there anyway in php i can group all the results by the earning month instead of indevidual sales?

now i understand you may think "sql is neeed here", but ive tried using sql and i cannot get monthly earnings to output, months are fine, but instead of summing up the monthly earning, it sums up the whole tables earnings column

hope ive explained well enough?

How about

$q = mysql_query("SELECT sum(earnings_column_name) as earnings, date_format(date_column_name, '%b %Y') as month FROM table GROUP BY month");
while($r = mysql_fetch_array($q))
{
    echo 'Month: '.$r['month'].' --> Earning:'.$r['earnings'];
    echo '<hr>';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.