Welcome Guest, Not a member yet? Register   Sign In
help .... I got a FATAL ERROR -- probably syntax
#1

[eluser]JPrieto[/eluser]
Code:
<html>
<head>
  <title><?php echo $title; ?></title>
</head>
<body>

<h1> &lt;?php echo $heading; ?&gt; </h1>

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

&lt;/body&gt;
&lt;/html&gt;

but i get this error:
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\codeigniter\system\application\views\blog_view.php on line 9

i was following along tutorial video 2 - and all was fine -- ii can able to view and create entries into the database table

i spend 30-40 minute trying to figure out was is wrong here but i cant find it

would appreaciate your assistance

please

ps: after the foreach statement i placed a : (not a Wink since that is what is in the video
#2

[eluser]Thorpe Obazee[/eluser]
are you sure you can retrieve data from the table? Try check if there's a result before using ->result().
#3

[eluser]JPrieto[/eluser]
yes, i am sure
i was follwing the tutorial video 2
and i was able to
connect/retrieve
view and create
into the table
#4

[eluser]Thorpe Obazee[/eluser]
Post your code. Have you used ->result() already in the controller or model?
#5

[eluser]JPrieto[/eluser]
Code:
&lt;?php
Class Blog extends Controller
{
    Function Blog()
    {
        parent::Controller();
    }
    
    Function index()
    {
       $data['title']= "My Blog Title";
       $data['heading']= "My Blog Heading";
       $data['query']= $this->db->get('entries');
       $this->load->view('blog_view',$data);
    }
}
?&gt;

QUESTION: is there supposed to be a space after the word foreach in the views file?
#6

[eluser]Thorpe Obazee[/eluser]
[quote author="JPrieto" date="1243577479"]
Code:
&lt;?php
Class Blog extends Controller
{
    Function Blog()
    {
        parent::Controller();
    }
    
    Function index()
    {
       $data['title']= "My Blog Title";
       $data['heading']= "My Blog Heading";
       $data['query']= $this->db->get('entries');
       $this->load->view('blog_view',$data);
    }
}
?&gt;
[/quote]

I doubt that you are retrieving data. Check the query you're using. Read the user_guide

[quote author="JPrieto" date="1243577479"]
QUESTION: is there supposed to be a space after the word foreach in the views file?[/quote]

Read the user guide
#7

[eluser]JPrieto[/eluser]
hi again
if i browse to

http://localhost/codeigniter/index.php/b...lding/view

it connects, retrieves, lists, edit, and deletes data

how else should i test the connection?
#8

[eluser]Thorpe Obazee[/eluser]
hmm... I don't know what was in my mind.. but I think I know now what's wrong.

Is this the line 9?
Code:
<p>&lt;?php echo $row->body; ?&gt;</p>
If it is, you don't have a 'body' field or an alias of the field.

If it's not, then you should probably post more info.
#9

[eluser]JPrieto[/eluser]
i do have a body field
i followed the video to the letter
it is why when i browse to http://localhost/codeigniter/index.php/b...lding/view
it connects, retrieves, lists, edit, and deletes data

this is a tough one
i've been googling also

nothing so far
#10

[eluser]Thorpe Obazee[/eluser]
what's line 9?

I don't think it's a tough one. You just need to post more info.




Theme © iAndrew 2016 - Forum software by © MyBB