CodeIgniter Forums

Full Version: Why am I getting this DB error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jleequeen[/eluser]
I can't for the life of me figure out why I keep getting the following error:

Quote: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 'distribution_lines' at line 1

distribution_lines

Below is my code. Any ideas from anyone would be great!

My controller:

Code:
class Report extends Controller {

    function Report() {
        parent::Controller();    
    }
    
    function view()    {
        $this->load->model('water_systems_model');
        $this->load->model('distribution_lines_model');
        $this->load->helper('form');
        
        $pwsid = $this->session->userdata('pwsid');
        $year = $this->session->userdata('year');
        
        $data['water_system'] = $this->water_systems_model->water_system_info($pwsid);
        $data['distribution_lines'] = $this->distribution_lines_model->get_distribution_lines($pwsid, $year);
        $data['bodyid'] = 'plan';
        $this->load->view('report/view', $data);
    }    
}

My Model:

Code:
class Distribution_lines_model extends Model {
    
    function Distribution_lines_model()    {
        parent::Model();        
    }
    
    function get_distribution_lines($pwsid, $year) {
        $this->db->where('pwsid', $pwsid);
        $this->db->where('year', $year);
        $this->db->order_by('type', 'asc');
        $query = $this->db->query('distribution_lines');
        return $query->result();
    }
}

My View:

Code:
....
<?php foreach($distribution_lines as $row) { ?>
    <tr>
        <td class="left">&lt;?php echo $row->type; ?&gt;</td>
        <td>&lt;?php echo $row->size; ?&gt;</td>
        <td>&lt;?php echo number_format($row->percent,2); ?&gt; %</td>
    </tr>
&lt;?php } ?&gt;
....

El Forum

[eluser]xwero[/eluser]
get instead of query Smile

El Forum

[eluser]jleequeen[/eluser]
@xwero

Geez. I need to be slapped. It's funny when you look at something 100 times and still can't see something so obvious.

El Forum

[eluser]xwero[/eluser]
I think we all know the feeling Wink