CodeIgniter Database Query Has An Error But I Don't See It
if ($this->input->get('beds'))
$where['Bedrooms'] = $this->input->get('beds');
if ($this->input->get('baths'))
$where['Bathrooms'] = $this->input->get('baths');
$min_price = ($this开发者_开发问答->input->get('min_price'))
? $this->input->get('min_price')
: '0';
$max_price = ($this->input->get('max_price'))
? $this->input->get('max_price')
: '10000000';
$q = $this->db->select("*")
->where('ListingPrice <=', $max_price)
->where('ListingPrice >=', $min_price)
->limit(10)
->get();
Do you? You can trust that all the values are there.
The error is:
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 'WHERE ListingPrice <= '100000' AND ListingPrice >= '0' LIMIT 10' at line 2
I don't use CodeIgniter but there doesn't seem to be a FROM
element to your query
You didn't specify the table you are querying from. Try setting the table name inside the get method or using the from()
method somewhere in your query.
->get('table_name');
Also, if you are just selecting everything ("*") you can leave out the select()
from your query because it will select everything by default.
Looks like you're mixing the MODEL within the CONTROLLER also try using the profiler to get more details on your 'error' => $this->output->enable_profiler(TRUE);
Otherwise you are missing the FROM:
$q = $this->db->select('*')->from('TABLE')....
精彩评论