Welcome Guest, Not a member yet? Register   Sign In
Stupid n00b question
#1

[eluser]Unknown[/eluser]
Hi all,

I am new to CI and I have just stated to play around with it and I have to say its fantastic. However I have run into a problem that I just can't seem to get around.

I was watching the intro videos on this site and looked at how to create a blog, so managed to create a database and connect it to my app and I created a view and a controller.
Now the problem I have is I can't seem to output the data from the data base in to my view?

All I get in Firefox is:

$body
$body
$body
$body
$body

or

Code:
Severity: Notice
Message: Undefined variable: body
Filename: views/blogview.php
Line Number: 9


I am on Windows 7 and running WAMP with PHP version 4.4.9.

Here is the code that's in my controller (blog):
Code:
<?php

class Blog extends Controller{

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

    function index(){
        
        $data['$title'] = "Hello and welcome to my blog";
        $data['query'] = $this->db->get('entries');

        $this->load->view('blogview', $data);      
    }
}

?>

And now the view (blogview):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php foreach($query->result() as $row):?&gt;
    <p>&lt;?php echo $body;?&gt;</p>
&lt;? endforeach; ?&gt;
    
&lt;/body&gt;
&lt;/html&gt;

Can someone please tell me where I am going wrong? I have tried my best at looking at the code but I just can't see what I am missing...

Sorry for the silly n00b question but I guess we all have to start somewhere Smile

Thanks in advance,
John
#2

[eluser]BrianDHall[/eluser]
You are gonna smack yourself, but like the error says - $body is undefined. I think you are perhaps looking for $row->body or $row['body'] depending on if $row is an array or an object, I can never recall (don't use those features anymore).




Theme © iAndrew 2016 - Forum software by © MyBB