Welcome Guest, Not a member yet? Register   Sign In
Displaying the SQL - Error debugging
#1

[eluser]bcarter[/eluser]
Hi there

I'm trying to display data but it's returning a blank page. I want to find out what the SQL is so that I can work out what the problem is but I don't know how.

Here's the code...

Model
Code:
<?php

class Sub_content_model extends Model {
    
    function Sub_content_model() {
        
        parent::Model();
    }
    
    function sub_content($id, $sid){
        
        $query3 = $this->db->get_where('sub_content', array('section' => $id, 'sub_content_ID' => '$sid'));
        return $query3->result();
    }
}


?>

View
Code:
<?php foreach ($query3 as $row) { ?>
    
    <?php echo $row->sub_content_title ?>
    
    <?php echo $row->sub_content ?>
    
<?php } ?>

<?php $this->load->view('footer') ?>

And the Controller
Code:
function information() {
        
        $id = '2';
        $sid = $this->uri->segment(3);
        $data['page_title'] = "Electrical Courses";
        
        $this->load->model('Nav_model');
        $data['query'] = $this->Nav_model->nav();
        
        $this->load->model('Subnav_model');
        $data['query2'] = $this->Subnav_model->subnav($id);
        
        $this->load->view('head', $data);
        
        $this->load->model('Sub_content_model');
        $data['query3'] = $this->Sub_content_model->sub_content($id, $sid);
        $this->load->view('information_view', $data);
    }

Can somebody help please?!!!

Thanks
#2

[eluser]danmontgomery[/eluser]
Code:
'$sid'

Shouldn't be in quotes. Strings with single quotes are translated literally.

If it's returning a blank page there's a PHP error, I would guess it's because you're calling ->result() without checking for a valid MySQL result first.

Code:
$query = $this->db->get_where(...);
if($query && $query->num_rows()) {
    return $query->result();
}

To view all of the queries run on the page, enable the profiler.

http://ellislab.com/codeigniter/user-gui...iling.html

Code:
$this->output->enable_profiler();




Theme © iAndrew 2016 - Forum software by © MyBB