Current query selects a list of dates from stats when there have been clicks during a time period and later checks other tables date by date for these dates:
$SQL = "SELECT DISTINCT DATE_FORMAT(time, '%Y-%m-%d') dt FROM stats WHERE ".$TimePeriod." ORDER BY ";
Problem is that there might be sales on dates where there are no clicks (returning visitors)... so i it possible to get dates from both stats and sales tables into one result field through some kind of JOIN and then check these results date by date.
e.g. something like this, but I get an error with this:
$SQL = "SELECT DISTINCT DATE_FORMAT(stats.time, sales.time, chargebacks.time, '%Y-%m-%d') dt FROM stats,sales,chargebacks WHERE ".$Time." ORDER BY dt";