CodeIgniter Forums
Why am I getting this DB error? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why am I getting this DB error? (/showthread.php?tid=9578)



Why am I getting this DB error? - El Forum - 06-30-2008

[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;
....



Why am I getting this DB error? - El Forum - 06-30-2008

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


Why am I getting this DB error? - El Forum - 06-30-2008

[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.


Why am I getting this DB error? - El Forum - 06-30-2008

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