Welcome Guest, Not a member yet? Register   Sign In
Error program
#1

[eluser]nnn[/eluser]
I'm new to this codeigniter can any one please solve me out!

This is controller.
<?php
class Ex extends CI_Controller{
function Ex(){
parent::__construct();
}
function see(){
$this->load->model('emp_model');
$data['query'] = $this->emp_model->emp_getall();

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

}
}
?>

This model.
<?php
class Emp_model extends CI_Model{
function __construct(){
parent::__construct();
}

function emp_getall(){
$this->load->database();
$query=$this->db->get('student');
return $query;
}
}
?>

This view.
<?php

foreach($data->result() as $row){
echo $row->name;
echo $row->id;
echo $row->branch;
echo "<br>";
}
?&gt;
#2

[eluser]xeroblast[/eluser]
try this in your controller

Code:
function Ex(){
parent::__construct();
}
change to
Code:
function __construct() {
parent::__construct();
}
#3

[eluser]nnn[/eluser]
Thank you.

i'm getting error as follows:

Fatal error: Call to a member function result() on a non-object in views\emp_view.php on line 3
#4

[eluser]Aken[/eluser]
Should be:

Code:
foreach ($query->result() as $row)

Read up on passing data to views to see why.
#5

[eluser]nnn[/eluser]
i tried getting same error
#6

[eluser]xeroblast[/eluser]
try this in your controller
Code:
$data[‘query’] = $this->emp_model->emp_getall();
change to
Code:
$data[‘students’] = $this->emp_model->emp_getall();

try this in your model
Code:
$query=$this->db->get(‘student’);
return $query;
change to
Code:
$query=$this->db->get(‘student’);
return $query->result();

and in your view, the loop
Code:
// if youre using foreach
foreach ( $students as $s ) { }
// if your using for
for ( $i=0; $i < count($students); $i++ ) { }
#7

[eluser]xeroblast[/eluser]
you cant use the result() if youre outside the $this->load->database();..
#8

[eluser]nnn[/eluser]
Every where ever i use result() i'm getting error as

Call to a member function result() on a non-object in that particular line.
#9

[eluser]nnn[/eluser]
foreach ($query->result() as $row)

in this loop other than 'query' if i use any other name its giving undefined variable
with same function error

then if i use foreach ($query as $row)
it gives Invalid arguement supply
#10

[eluser]nnn[/eluser]
none of the functions like result(), result_array()... are working either in model or view

what i need to include or where should i do alternation.

please guide me.




Theme © iAndrew 2016 - Forum software by © MyBB