i hope i can solve here Undefined property: Siswa::$siswa_model - php

,Message: Call to a member function get_paged_list() on null Filename: controllers/siswa.php
this my full code
http://pastebin.com/ZBHkBS8i
Problem solved,thanks to baci and bora

you shouldn't call the model like this
$siswas = $this->siswa_model->
get_paged_list($this->limit,$offset,$order_column,$order_type) ->result();
but like this
$this->load->model("siswa_model");
$result = $this->siswa_model->
get_paged_list($this->limit,$offset,$order_column,$order_type)
and in the model you should query the database end return the result, something like this
public function get_paged_list($limit,$order_column,$order_type)
{
$q_str = "select * from table ....etc ";
$q = $this->db->query($q_str);
return $q->result();
}
hope that helps

Related

i want to display value from database in codeigniter but i am getting errror

I want to display a value in view in CodeIgniter but I am getting several errors like trying to get the property on non-object. I think my code is correct but I am getting errors. Below is my code.
controller:
public function trainer($id)
{
$user_record = $this->db->query("select * from usr_data where usr_id=$id")->result();
$data['title'] = 'trainer Dashboard';
$data['user_record'] = null;
$data['active_courses'] = [];
$data['inprogress'] = [];
if(count($user_record)) {
$user_record = $user_record[0];
$data['title'] = ucwords($user_record->firstname).' Dashboard';
$data['user_record'] = $user_record;
$active_courses = $this->base_model->getTrainercourseAll($id);
$data['active_courses'] = $active_courses;
$inprogress = $this->base_model->getstaffinprogress($id);
$data['inprogress'] = $inprogress;
}
$this->load->view('trainer-dashboard', $data);
}
model:
public function getstaffinprogress($user_id) {
$result=$this->executeSelectQuery("select AVG(m.percentage) from object_data o, ut_lp_marks m where o.obj_id=m.obj_id and o.type='crs' and m.status=1 ");
return $result;
}
view:
<h3>Avg inprogress:<?php echo "<span style='color:#ff00ff;font-family:verdana;'>".$inprogress->percentage."</span>";?></h3>
I want to display the column percentage which is coming from database.above code is in the controller, model and view.i thought my controller code is wrong.
Anyone help me to get rid of this error. I want to display a value in view in CodeIgniter but I am getting several errors like trying to get the property on non-object. I think my code is correct but I am getting errors. Below is my code.
Try this in your view file,
if(isset($inprogress)){
echo $inprogress->percentage;
}
Then your code look like this,
<h3>Avg inprogress:<?php if(isset($inprogress)){ echo "<span style='color:#ff00ff;font-family:verdana;'>".$inprogress->percentage."</span>";}?></h3>
Then call the controller function. I think inprogress is not set at the first time.
If it doesn't work, try to var_dump($inprogress) in controller and check value and type.
And try this code in your model. Query also seems not correct
public function getstaffinprogress($user_id) {
$this->db->select_avg('ut_lp_marks.percentage');
$this->db->where('ut_lp_marks.obj_id', $user_id);
$this->db->where('object_data.type', 'crs');
$this->db->where('ut_lp_marks.status', 1);
$this->db->join('object_data', 'object_data.obj_id = ut_lp_marks.obj_id');
$query = $this->db->get('ut_lp_marks');
return $query->result_array();
}
I assume that your db is ut_lp_marks. Then var_dump array and check data is correct first. Then access array element.
public function getstaffinprogress($user_id) {
$result = array();
$query=$this->db->query("select AVG(m.percentage) from object_data o, ut_lp_marks m where o.obj_id=m.obj_id and o.type='crs' and m.status=1 ");
foreach($query->result() as $row){
$result = $row;
}
return $result;
}
Also check $inprogress->percentage exists before print in view.

How to get more than one parameter using codeigniter

I have problem to get more parameter when I do a searching method.
This is my url ->
http://localhost:8080/sewarumah/search/searchIndex?state=1&city=2&poskod=90002&jenisRumah=Banglo0&bilangan=2
So here I want get all parameter and pass to model.
This is my controller
public function index($state,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan)
{
$state=$this->input->get("state");
$data['search_result'] = $this->m_search->searchIndex($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan);
$this->load->view('senarai-rumah', $data,$state);
}
And this is my model
public function searchIndex($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan){
$sql = "select * from house_rent where houseStateId = ? and houseDistrictId = ? and housePostcode = ? and houseType = ? and housePeople = ?;";
$query = $this->db->query($sql, array($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan));
return $query->result();
}
So the error show
Message: Undefined variable: state
None of those variables are actually defined, unless you do them in the route (which seems silly). You can get them all from the $this->input->get() method like so:
public function index()
{
$state=$this->input->get("state");
$city=$this->input->get("city");
$postcode=$this->input->get("postcode");
$jenisRumah=$this->input->get("jenisRumah");
$bilangan=$this->input->get("bilangan");
$data['search_result'] = $this->m_search->searchIndex($state,$city,$postcode,$jenisRumah,$bilangan);
$this->load->view('senarai-rumah', $data, $state);
}

cant display the data from controller

My problem is that I can't get data in database but if I use var_dump() I have data. This is the error:
A PHP Error was encountered Severity: Notice Message: Undefined index: projectid Filename: views/accounting_status.php Line Number: 46
This is my View
This page was accesed incorrectly.
<div class="well">
<p><h1><?=$p['projectid']?></h1></p>
<p><?=$p['code']?></p></div>
This is my Controller
function id($projectid){
$data['p'] = $this->Accounting_Model->get_awardedid($projectid);
//echo "<pre>".print_r($data)."</pre>";
$this->load->view('tmp_header');
$this->load->view('accounting_status',$data);
}
This is my Model
function get_awardedid($projectid){
$this->db->select('*')->from('projects')
->join('customer', 'projects.customerid = customer.customerid')
->join('employees', 'projects.endorse_by = employees.employeeid')
->where(array('acctg'=>1,'projectid'=>$projectid))
->order_by('datecreated', 'desc');
$query = $this->db->get();
return $query->result_array();
}
If the result will be a single row then change on model as follows:
function get_awardedid($projectid){
$this->db->select('*')->from('projects')
->join('customer', 'projects.customerid = customer.customerid')
->join('employees', 'projects.endorse_by = employees.employeeid')
->where(array('acctg'=>1,'projectid'=>$projectid))
->order_by('datecreated', 'desc');
$query = $this->db->get();
return $query->row_array();
}
If result is multiple records, then use for loop to print the values in view.
<div class="well">foreach($p as $value){<p><h1><?=$value['projectid']?></h1></p><p><?=$value['code']?></p>}</div>

Getting error while value is link

I am getting the following error.
Message: Trying to get property of non-object
Table Structure:
name ='fb' value='https://www.facebook.com/mypage'
Model:
function get_fb_url(){
$query=$this->db->select('value');
$query=$this->db->from('preferences');
$query=$this->db->where('name','fb');
return $this->db->get()->row();
}
Controller:
$data['fb_url']=$this->Home_model->get_fb_url()->value;
View:
<li><img src="css/imgs/fb.png" /></li>
When i run my page it give me error
Message: Trying to get property of non-object
only when if value in the table is link like above, if its simple text then text properly show on page.
How Can i get rid off this error?
Instead of echo use return type
Change
echo $this->db->get()->row();
to
return $this->db->get()->row();
And add $ before variable name in view
<a href="<?php echo $fb_url;?>"
UPDATED
Change your model code to
function get_fb_url() {
$this->db->select('value');
$this->db->from('preferences');
$this->db->where('name', 'fb');
return $this->db->get()->row();
}
you must try like this:
function get_fb_url() {
$this->db->select('value');
$this->db->from('preferences');
$this->db->where('name', 'fb');
$query = $this->db->get();
return $query->row();
}
and in Controller:
$result = $this->Home_model->get_fb_url();
//try print $result, it must be an stdObject
$data['fb_url']=$result->value;
it is because in $data['fb_url']=$this->Home_model->get_fb_url()->value; / differentiate the link to the other function, that's why u r getting this error.
get_fb_url is returning object array not object. so you have to return value from method.
function get_fb_url()
{
$query=$this->db->select('value');
$query=$this->db->from('preferences');
$query=$this->db->where('name','fb');
return $this->db->get()->row()->value;
}
and than
$data['fb_url']=$this->Home_model->get_fb_url();
In Your model do this
public function get_fb_url() {
$this->db->select('value');
$this->db->from('preferences');
$this->db->where('name','fb');
$query = $this->db->get();
$row = $query->row();
return $row;
}
In Controller :
$data = array();
$result = $this->Home_model->get_fb_url();
$data['fb_url'] = $result->value;
$this->load->view('your_view',$data);
In View :
echo $fb_url;

codeigniter error with selecting data from table

I cant figure out whats wrong with my model, it said a Fatal Error occured.
Here's my model file:
function getName($no_ktp){
$this->db->select('nama')->from('dt_prbd')->where('no_ktp', $no_ktp);
$qry_getName = $this->db->get();
if ($qry_getName->num_rows() > 0) {
foreach ($qry_getName->result() as $data_getName){
$hasil_qry_getName[] = $data_getName;
}
return $hasil_qry_getName;
}
}
I got this error.
Fatal error: Call to a member function num_rows() on boolean in C:\xampp\[APP_PATH]\M_hrd_apps.php on line 25
I thought the error is in the query, so I changed it into this:
$qry_getName =
$this->db->select('nama')
->from('dt_prbd')
->where('no_ktp', $no_ktp)
->get();
but the error is the same,
Call to a member function num_rows() on boolean
Can anyone help me please?
Tr this
function getName($no_ktp){
$this->db->select('nama')->from('dt_prbd')->where('no_ktp', $no_ktp);
$qry_getName = $this->db->get();
$result = $qry_getName->result();
return $result;
}
}
Try this
In Model
function getName($no_ktp)
{
$query = $this->db->query("SELECT nama FROM dt_prbd WHERE no_ktp= '$no_ktp'");
$result = $query->result_array();
$count = count($result);
if (empty($count))
{
$log = 0;
return $log;
}
else
{
return $result;
}
}
In controller
$result = $this->Model_name->getName();
if($result == 0)
{
echo 'Data Is empty';
}
else
{
$data['name'] = $result;
#rest of your code
}
EDIT 01
To configure your database
go to config/database.php in bottom of page define
Databse name
Mysql Username
Mysql Password
all problem solved, there is no error in code. i try to re-create the db, and then all script turn out like what i expect.
thanks for all help Deep Parekh and Abdulla

Categories