Welcome Guest, Not a member yet? Register   Sign In
white screen of death?
#1

[eluser]jshultz[/eluser]
I'm not sure why this is happening. I'm trying to retrieve data from a table in a mysql db. one way it works, but the other way it doesn't. And when it doesn't work, all I get is white screen with no error messages.

Here's how it definitely works:

If i place the query in the site controller I have no problems.

Code:
function project_list()
    {
          if (!$this->tank_auth->is_logged_in()) {
            redirect('/auth/login/');
          } else {
              
            $data['query'] = $this->db->get('projects');

            
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $this->load->view('header', $data);
            $this->load->view('menu');
            $this->load->view('sidebar', $data);
            $this->load->view('project-list-view', $data);
            $this->load->view('footer');
        }

    }

I never use the model and instead in project-list-view i have this code:

Code:
<div id="content" class="span-16 last">

    <h1>We Get You Noticed!</h1>
    
    &lt;?php foreach($query->result() as $row): ?&gt;
    
    <h3>&lt;?=$row->project_name?&gt;</h3>
    <p>&lt;?=$row->due_date?&gt;</p>
    
    &lt;?php endforeach; ?&gt;

</div>

And everything works just fine. However, if I instead the project_model model like so:

Code:
class Project_model extends Model {

function getAll() {
    $q = $this->db->get('projects');
    
    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
            $data[] = $row;
            
        }
        return $data;
    }

and in site.php the only changes I make is to remove this:

$data['query'] = $this->db->get('projects');

and replace it with this:

Code:
$this->load->model('Project_model');
$data['rows'] = $this->Project_model->getAll();

then the view fails to load and all I get is the white screen.

I'm still just learning so i'm probably missing something obvious but i've been watching video after video over and over and reading all i can find. If I was at least getting some kind of error message that'd be nice but i'm not. So, it's come down to trial and error to see what works. Which isn't bad of course, but it does suck up a lot of time. Sad
#2

[eluser]garymardell[/eluser]
Well for some reason when you use your model you are just returning the rows. However you view is still trying to loop through the $query->result() which will cause a problem.

I suggest in your model you do this:

Code:
function getAll() {
  return $this->db->get('projects');
}

Then your controller has access to the num rows property and your view will too.

In your controller do:

Code:
$this->load->model('Project_model');
$data['query'] = $this->Project_model->getAll();

And that should work.
#3

[eluser]jshultz[/eluser]
You're right. That worked!

I was following along in a video tutorial and it was just frustrating me to heck that I couldn't get it to work. I'd scrub forwards and backwards in the video comparing what they had done with what I had done but remember to change table names, etc. and it just wouldn't work.

thank you very much!
#4

[eluser]wabu[/eluser]
As general advice, if you're stuck with a white screen check your web server's error log for messages.




Theme © iAndrew 2016 - Forum software by © MyBB