Code ignitier MySQL query
I'm getting an error with this function:
Controller
$data['carSubwoofers'] = $this->db->get_where("department = 'MOBILE AUDIO'
AND class = 'CAR STEREO'
AND subclass
IN ('SO CAR STEREO','SUBS','SO SUBS')")->result();
$this->load->view('Category/carSubwoofers',$data);
View
foreach($data->result() as $row) { ?>
<?php echo $开发者_运维百科row->modelNumber; ?>
<?php echo $row->name; ?>
<?php } ?>
Code igniter shoots out this:
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 ''MOBILE AUDIO' AND class = 'CAR STEREO' AND subclass IN ('SO CAR STEREO' at line 2
SELECT * FROM (department
= 'MOBILE AUDIO' AND class = 'CAR STEREO' AND subclass IN ('SO CAR STEREO', 'SUBS'
, 'SO
SUBS'))
Filename: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\CodeIgniter_2.0.2\system\database\DB_driver.php
Line Number: 330
You can chain your conditionals together to make it look cleaner too.
$this->db->where('department', 'MOBILE AUDIO')->where('class', 'CAR STEREO')->where_in('subclass', array('SO CAR STEREO','SUBS','SO SUBS'))->get('tableName');
Your get_where() is totally off the documentation...
$query = $this->db->get_where('TABLE', array('id' => $id), $limit, $offset);
from the docs
so you would want something like $this->db->get_where("TABLE", array('MOBILE AUDIO' => 'CAR STEREO','class' =>'CAR STEREO'...)
Don't know codeigniter, but it looks like you've forgotten to assign $this->db a table to query.
精彩评论