Welcome Guest, Not a member yet? Register   Sign In
Call to a member function result() on a non-object
#1

[eluser]mikka23[/eluser]
Well the title is extremely vague but thats because Im not sure what Im doing Big Grin. Anyways. I am receiving the following error:

Code:
Call to a member function result2() on a non-object on line 20.

Basically i am making a cms. These two php above are to edit pages currently in the database. So you go to a url with the id in the url and it displays a form with the current details which are in the database for that id. That was fine and working perfectly. Only problem was encountered when I added two new columns into my database: parent and sibling. I want a select field with the info from 'parent' for the page we are editing. Thats fine and working. The problem arises when I want to show every 'slug' for every row in the same table apart from the slug of the page we are editting and any rows where 'parent' does not equal "none"(default value for column). I do not know how to show this because I used a where clause in the database get command therefore I don't have the information from the database for any other rows apart from the one we are editting (id = uri section 4).

All help is greatly appreciated. I am a PHP noob so if you need me to explain anything a little please say as I realise my explanation is really vague.


I was previously trying:

in controller:
Code:
$this->db->where('id', $this->uri->segment(4));
    $data['query'] = $this->db->get('pages');
    $this->load->view('managepageview', $data);    
    
    $this->db->where('parent', 'none');
    $pdata['parental'] = $this->db->get('pages');
    $this->load->view('managepageview', $pdata);

in managepageview:
Code:
<?php
foreach($query->result() as $row){
echo "<h2>Manage Page - $row->title</h2>";
echo form_open('admin/pages/managepage');

echo "<h4>Title</h4>
&lt;input type='text' id='title' name='title' value='$row-&gt;title' size='50' />

<h4>Slug</h4>
&lt;input type='text' id='slug' name='slug' value='$row-&gt;slug' size='50' />

<h4>Content</h4>
&lt;textarea id='content' name='content' cols='80' rows='15'&gt;";
echo ( htmlentities($row->content));
echo "&lt;/textarea&gt;
<h4>Parent:</h4>
<select name='parent'>
  <option value=' <$row->parent'>$row->parent</option>";
  
        foreach($parental->result() as $bow){
           echo "<option value='$bow->slug'>$bow->slug</option>";
            }
echo "</select>
&lt;input name='id' type='hidden' value=' $this-&gt;uri->segment(4); ?&gt;'>
<p>&lt;input type='submit' value='Update' /&gt;&lt;/p>
&lt;/form&gt;";
echo form_open('admin/pages/deletepage');
echo "&lt;input name='id2' type='hidden' value='";
echo $this-&gt;uri->segment(4);
echo "'><p>If you want to delete the page click the button below:</p>
    <p>&lt;input type='submit' value='Delete' /&gt;&lt;/p>
&lt;/form&gt;";
}
?&gt;

It doesn't show anything for the second set of results however, apart from this part it works perfectly:
Quote:&lt;?php foreach($parental->result() as $bow):?&gt;
<option value=" &lt;?=$bow->slug?&gt;">&lt;?=$bow->slug?&gt;</option>
&lt;?php endforeach; ?&gt;
#2

[eluser]NogDog[/eluser]
I do not know enough about the code to know where the fix needs to go (or what exactly it should be), the problem is that at that point in the code $parental is not an object. For it to be one it would have had to be instantiated at some point via the new keyword, or else be a reference/copy of an existing object variable. Do you know where the $parental variable is supposed to get set?
#3

[eluser]mikka23[/eluser]
You see in my controller. Parental is a mysql query of the pages table when column parent is equal to none.
#4

[eluser]Colin Williams[/eluser]
The first time you load that view, the $data array supplied has no 'parental' index. Only the second time you load the view does it have this index. Just get rid of that first view load. It's superfluous.
#5

[eluser]mikka23[/eluser]
Thanks! Was such a simple error.
#6

[eluser]Colin Williams[/eluser]
You are welcome. It usually is pretty simple...




Theme © iAndrew 2016 - Forum software by © MyBB