Welcome Guest, Not a member yet? Register   Sign In
Getting a blank white page when using a model to connect with db
#1

[eluser]exceedstudios[/eluser]
I'm fairly new to CI and I've been having alot of trouble trying to use the MVC when trying to use database functionality. I have no problem when I do it just with the controller and view. I keep getting that blank white page when I try to load some fields from my db.

This is my code:

The Model:
Code:
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Homemodel extends Model {

    function Homemodel()
    {
        parent::Model();
    }
    
    function musicvideos()
    {
        $query = $this->db->get('clips', 4);
           return $query->result();
    }
    

}


Controller:
Code:
class Home extends Controller {

    function Home()
    {
        parent::Controller();
    }

    function index()
    {
        $data['title'] = "Welcome";
        
        $this->load->model('homemodel', '', TRUE);
        $data['query'] = $this->homemodel->musicvideos();
        
        $this->load->view('home_view', $data);
    }
}

The View
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>

<?php foreach($query->result() as $row): ?>

    &lt;?php echo $row->filename; ?&gt;<br>

&lt;?php endforeach; ?&gt;

&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]Michael Wales[/eluser]
A blank white screen almost always means a PHP error (usually syntax) - is there any other relevant code your can share with us? I didn't see any errors in this copy.
#3

[eluser]exceedstudios[/eluser]
That is all the code. I run apache on a linux machine with mysql... I'm really stuck.
#4

[eluser]exceedstudios[/eluser]
Just to let you know, the title displays correctly but everything else is just blank? any ideas?
#5

[eluser]exceedstudios[/eluser]
I'm really stuck, can someone please help me with this issue?
#6

[eluser]Rick Jolly[/eluser]
Try this in your view:
Code:
&lt;?php foreach($query as $row): ?&gt;

    &lt;?php echo $row->filename; ?&gt;<br>

&lt;?php endforeach; ?&gt;
You call query->result(); in your model, so you can't and don't need to call it again in your view.
#7

[eluser]exceedstudios[/eluser]
Thanks so much, that was the problem!




Theme © iAndrew 2016 - Forum software by © MyBB