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

[eluser]face1m[/eluser]
Wow! I have been working on this all day. I could have had my site done by now if i wasn't using codeigniter. Feel the frustration? What seems to work on one site does not work on another. Here is the code... and thanks for feeling the frustration.

<?php

class Home extends Controller {

function __construct()
{
parent::Controller();


}

function index()
{



$data['query'] = $this->hotlotto_model->get_last_ten_entries();

print_r($data);<------ this prints out the last 10 entries and it works


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

}
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
?&gt;
----------------------------------------------------------------

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;How to Win Hot Lotto&lt;/title&gt;


&lt;/head&gt;
&lt;body&gt;
<h1>How to Win Hot Lotto!</h1>



&lt;?php foreach ( $query->result() as $row ): ?&gt; <---This is the error Call to a member

function result() on a non-object on line 16 (this is line 16)

<h3>&lt;?=$row->DRAWDATE?&gt;</h3>
<p>&lt;?=$row->N1?&gt;</p>
<p>&lt;?=$row->N2?&gt;</p>
<p>&lt;?=$row->N3?&gt;</p>
<p>&lt;?=$row->N4?&gt;</p>
<p>&lt;?=$row->N5?&gt;</p>
<p>&lt;?=$row->hball?&gt;</p>


<hr />
&lt;?php endforeach; ?&gt;
<p><br />Page rendered in {elapsed_time} seconds</p>

&lt;/body&gt;
&lt;/html&gt;
_______-------------------------------------------------------

this is the result of the print_r()

Array ( [query] => Array ( [0] => stdClass Object ( [DRAWDATE] => 2002-04-10 [N1] => 3 [N2] => 5 [N3] => 6 [N4] => 16 [N5] => 33 [hball] => 5 )

The model is loaded using the auto load file and the database lib.
Thanks for overlooking the frustration!
rick
#2

[eluser]danmontgomery[/eluser]
$this->hotlotto_model->get_last_ten_entries() isn't returning a mysql_result object, which is what class the result() function is a member of. Change
Code:
foreach($query->result() as $row)
to
Code:
foreach($query as $row)
#3

[eluser]face1m[/eluser]
That did it! Now i can put some of my hair back in.

thanks
rick




Theme © iAndrew 2016 - Forum software by © MyBB