[eluser]snowstar[/eluser]
Thanks for the reply,
I got this error back
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=>'2010-01-01' AND `date`<='2010-09-29' ORDER BY `date` ASC' at line 3
SELECT DISTINCT `date` FROM `crm_sales` WHERE `date`=>'2010-01-01' AND `date`<='2010-09-29' ORDER BY `date` ASC
I haven't used => in a query before but the data field type is date
[quote author="toopay" date="1301595207"]
Code:
function date_to_date($start, $end)
{
$query = 'SELECT DISTINCT `date`
FROM `crm_sales`
WHERE `date`=>'.$this->db->escape($start).' AND `date`<='.$this->db->escape($end).'
ORDER BY `date` ASC';
$data = $this->db->query($query);
$date_range = $data->result_array();
$i=count($date_range);
$j=0;
while ($j<$i)
{
$query = 'SELECT `totalprice`
FROM `crm_sales`
WHERE `date`='.$date_range[$j]['date'].'
ORDER BY `totalprice` ASC';
$data = $this->db->query($query);
$totalprice_list = $data->result_array();
$res[$j] = array(
'date' => $date_range[$j]['date'],
'total_itemprice => count($totalprice_list),
'grouped_totalprice' => $totalprice_list,
);
$j++;
}
return $res;
}
If your 'date' field formated with full time stamp like '2011-01-04 00:00:01', you actually can do it better and cleaner, by set it directly in your query, with 'COUNT()', 'GROUP_CONCAT()' and 'GROUP BY'.[/quote]