Welcome Guest, Not a member yet? Register   Sign In
Help with Active Records
#1

[eluser]snowstar[/eluser]
Hello All,

I am having trouble with a query, i'm not sure if i'm writing it correctly. The problem is with my where statement

Code:
$this->db->select('totalprice, date');
$this->db->where('date' BETWEEN '.$this->db->escape($start).' AND '.$this->db->escape($end).');
$this->db->order_by('date', 'desc');
$query = $this->db->get('crm_sales');

return $query->result();

Can any one help?
#2

[eluser]InsiteFX[/eluser]
For one you need to read the CodeIgniter User Guide on the where method! Your where method is completily wrong.

2) you do not need to use escape, Active Record automatically escapes all data!

InsiteFX
#3

[eluser]snowstar[/eluser]
I used the follow method to fix the solution

Code:
$query = 'SELECT `totalprice`, `date`
FROM `crm_sales`
WHERE `date` BETWEEN '.$this->db->escape($start).' AND '.$this->db->escape($end).'
ORDER BY `date` ASC';
        
$data = $this->db->query($query);
        
return $data->result();

Was not able to figure out how to do the query with active records
#4

[eluser]Unknown[/eluser]
Edit:

Code:
$this->db->where('date' BETWEEN '.$this->db->escape($start).' AND '.$this->db->escape($end).');

To

Code:
$this->db->where('date BETWEEN \''.$this->db->escape($start).'\' AND \''.$this->db->escape($end).'\'');
#5

[eluser]toopay[/eluser]
I think, you can use both active records and general SQL Query, and there's nothing wrong about choosing one of them. It should be this way, in active records...
Code:
$this->db->where(array('date >=' => $start, 'date <=' => $end));




Theme © iAndrew 2016 - Forum software by © MyBB