Error trying to fetch data from 2 tables codeigniter - php

I gotta fetch data from 2 tables.. My tables are "Study","Users" and "Subjects"
"Study" includes:(id, user_id[is the foreign key to the column "id" of the table "Users"], subject_id[is the foreign key to the column "id" of the table "Subjects"], grade, date)
"Users" includes:(id,username,name,lastname,password,type,status,date)
"Subjects" includes:(id, career_id, name, description, hours)
I wanna get something like this at the end:
I got this errors:
Here is my code:
My view file ("home"):
<html>
<head>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 align="center">TABLE:Study</h2>
<input id="busqueda_tabla" type="text">
<table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
<thead>
<th>id</th>
<th>User</th>
<th>Subject</th>
<th>Grade</th>
<th>Date</th>
<th>Action</th>
</thead>
<tbody>
<?php
if (count($records) > 0 && $records != false) {
foreach($records as $record) {
echo "<tr>
<td>".$record['id']."</td>
<td>".$record['user']."</td>
<td>".$record['subject']."</td>
<td>".$record['grade']."</td>
<td>".$record['date']."</td>
<td align='center'>
<button type='button' class='btn btn-primary'>EDITAR</button></a> |
<button type='button' class='btn btn-danger'>BORRAR</button></a>
</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
Here is my Controller file ("Home"):
<?php
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model("Crudmodel");
}
public function index(){
# get all data in Study table
$selectStudys = $this->Crudmodel->selectStudys();
foreach ($selectStudys as $key => $study)
{
# get UserNames
$user = $this->Crudmodel->getName($study['user_id']);
#get Subject Names
$subject = $this->Crudmodel->getSubName($study['subject_id']);
#append both NEW VALUES to same array
$data[$key]['user_id'] = $user[0]['username'];
$data[$key]['subject_id'] = $subject[0]['name'];
}
$data['records'] = $selectStudys;
$this->load->view('home', $data);
}
}
?>
And my Model file ("Crudmodel"):
<?php
class Crudmodel extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();
}
function selectStudys()
{
$query= $this->db->query("SELECT * FROM Study");
$result = $query->result_array();
return $result;
}
function getName($name)
{
$query= $this->db->query("SELECT username FROM Users WHERE id = $name ");
$result = $query->result_array();
return $result;
}
function getSubName($subject)
{
$query= $this->db->query("SELECT name FROM Subjects WHERE id = $subject ");
$result = $query->result_array();
return $result;
}
}
?>
Hope you can help me :/

Iam changed your query to join query, Simply change your code to below
public function index(){
# get all data in Study table
$query = $this->db->query("SELECT sd.user_id as id,sd.grade as grade,sd.date as date,sd.subject_id as subject,ur.username as user FROM Study as sd,Users as ur,Subjects as sb WHERE ur.id=sd.user_id and sb.id=sd.subject_id");
$result = $query->result_array();
$data['records'] = $result;
$this->load->view('home', $data);
}
and now run the code

Undefined indexes and trying to get property non-object more or less means the same thing which is you are not getting proper data or the variables or indexes you are trying to get are not initialized or undefined and cause of this can be error in query or blank data return by query you are running.
i would like to request you to pull your query data like this
$check = $this->db->query("SELECT * FROM SOMETHING AND YOUR CONDITION AND STUFF HERE");
if($check->num_rows()>0){
$result = $check->result();
return $result;
}else{
return false; // or anything you want.
}
let say this query function is stored in model and you are calling your model like this
$someVariable = $this->model_name->function();
if($someVariable!==FALSE){
// handle
}else
{
// handle
}
in the end, not sure why, but i also counter problems with double quotes sometime, YES I KNOW.. variable inside double quotes work, I'm just saying sometime... at least it happens with me, so i would like to request last thing. try debugging your query like this, currently you have
"SELECT * FROM TABLE WHERE THIS = $THAT"
Change this to
"SELECT * FROM TABLE WHERE THIS = '".$THAT."'"
I hope it will work out for you!.
EDITED:
(Sorry that i failed to show example from your own code)
Your Model file
<?php
class Crudmodel extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();
}
function selectStudys()
{
$query= $this->db->query("SELECT * FROM Study");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = "";
// or anything you can use as error handler
return $result;
}
}
function getName($name)
{
$query= $this->db->query("SELECT username FROM Users WHERE id = $name ");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = "";
// or anything you can use as error handler
return $result;
}
}
function getSubName($subject)
{
$query= $this->db->query("SELECT name FROM Subjects WHERE id = $subject ");
if($query->num_rows()>0){
$result = $query->result_array();
}else{
$result = "";
// or anything you can use as error handler
return $result;
}
}
function CombineResults($subject, $name){
// you can also use this
$query = $this->db->query("SELECT sub.name, user.username FROM Subjects sub, Users user WHERE sub.id=$subject AND user.id = $name");
if($query->num_rows()>0){
return $query->result();
}else{
return "";
// or anything you can use as error handler
}
}
}
?>
Your controller file
public function index(){
# get all data in Study table
$selectStudys = $this->Crudmodel->selectStudys();
// we have condition on this model method/function we can validate
// response comming from this method and add handler just like we did
// for queries. your main problem can be this
foreach ($selectStudys as $key => $study)
{
# get UserNames
$user = $this->Crudmodel->getName($study['user_id']);
#get Subject Names
$subject = $this->Crudmodel->getSubName($study['subject_id']);
#append both NEW VALUES to same array
if(!empty($user[0]['username'])){
$data[$key]['user_id'] = $user[0]['username'];
// your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here
}else{
$data[$key]['user_id'] = ''; // or anything as your else condition you can use as error handler
}
if(!empty($subject[0]['name'])){
$data[$key]['subject_id'] = $subject[0]['name'];
// your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here
}else{
$data[$key]["subject_id"] = "";
// or anything you can use as error handler
}
}
$data['records'] = $selectStudys;
$this->load->view('home', $data);
}

Related

I need to call a controller function inside a view -Codeigniter

I need to call a function from view to echo a value. I use following code,
Controller (test_controller)
public function displayCategory()
{
$this->load->model('Model_test');
$data['categories'] = $this->Model_test->getCategories();
$this->load->view('test_view', $data);
}
public function display($id)
{
$this->load->model('Model_test');
$name= $this->Model_test->getName($id);
return $name;
}
Model (Model_test)
function getCategories() {
$query = $this->db->query("SELECT * FROM category");
if ($query->num_rows() > 0) {
return $query->result();
} else {
return NULL;
}
}
function getName($userId) {
$query = $this->db->query("SELECT name FROM user where id = '$userId' ");
if ($query->num_rows() > 0) {
return $query->row()->name;
} else {
return NULL;
}
}
View
<div id="body">
<?php
foreach ($categories as $object) {
$temp = $this->test_controller->display($object->id);
echo $object->title . " ". $object->no . $temp . '<br/>';
}
?>
</div>
but some error when running the code.
error Message: Undefined property: CI_Loader::$test_controller in view
I am not sure if you use CodeIgniter 2 or 3.
Anyway, basically you don't want to use anything inside View files except perhaps helper function(s) or some kind of "presenter" layer (that should be called inside controller I guess).
Solution using Join
Go and read this manual page and search for join. There you can learn about implementation of SQL join directive.
You want to modify this (getCategories()) function so it returns data that you require
function getCategories() {
$this->db->select('category.title, category.no, user.name as username')
->from('category')
->join('user', 'user.id = category.id');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return NULL;
}
}
and in view you can get your username like this
foreach ($categories as $object) {
echo $object->title . " ". $object->no . $object->username . '<br/>';
}
I am not 100% sure so please post comments I will edit this answer later.
Solution "breaking rules"
https://stackoverflow.com/a/24320884/1564365
general notes
Also consider naming your tables using plural so categories, users...
Also it is a bad practise to use "category.id as user.id" (storing user id inside category table in "id" field) instead you shold use either a pivot table or in case of 1:1 relation field "user_id".

How make count comment with codeigniter,

I'm working on a project. how to calculate comment by id?
example
controler:
public function comments() {
$id_alat = $this->db->where('id_alat');
$com = $this->mcrud->getComent($id_alat);
$com = $this->mcrud->getComent($id_alat);
$data = array (
'com' => $com,
'content' => 'instrument/instrument');
$this->load->view('layouts/wrapper', $data);
}
models:
public function getComent($id_alat) {
$sql = "SELECT count (*) as num FROM WHERE tbcoment $id_alat tbcoment.id_alat = {}";
$this->db->query($sql);
}
view:
comments: <?php echo $com; ?>
Use following code for model
Your Model
public function getComent($id_alat)
{
$sql = "SELECT count (*) as num FROM WHERE tbcoment.id_alat = '$id_alat'";
$res=$this->db->query($sql)->row_object();
return $res->num;
}
Note: Don't use spaces inside php tags and variables.
Ex01: $ id_alat should come $id_alat
Ex02: $ this-> mcrud-> getComent ($ id_alat); should come $this->mcrud-> getComent($id_alat);
Code Example
In controller
function comments () {
$id_alat = '';//Asign data to here
$data['com'] = $this->Model_name->getComent($id_alat);
$data['content'] = 'instrument / instrument';
$this->load->view ('layouts/wrapper', $data);
}
In Model
function getComent($id_alat) {
$query =$this->db->query("SELECT * FROM table_name WHERE tbcoment='$id_alat'");//cahnge table name, and argument that you want
$result = $query->result_array();
$count = count($result);
return $count;
}
In view
comments: <?php echo $com; ?>
you can also use this code:
$this->db->where('id',$id)
->from('table_name')
->count_all_results();
this can be used either on MVC(Model, View, Controller);
you can find this code on the user guide

Codeigniter: this->datatables->select(sample)->from(sample)->where()

Please help me. i can not use my dataTable properly. what I want to do is
select from table and use thewherefunction. but i cant do it properly.
here is my controller code
public function reporttable ()
{
$zz = array('empnumber' => $this->input->post('empnumber'));
//$this->db->order_by("surname", "asc");
$this->datatables->select('date_auto,particulars,earned_VL,aul_VL,balance_VL,aulx_VL,earned_SL,aul_SL,balance_SL,aulx_SL,date_leave,action_taken')
->from('tblreport')->where($zz);
echo $this->datatables->generate();
}
this is my supposed query:
select * from tblreport where empnumber = (the empnumber in my textbox.)
there, i get a value from a textbox to my view. but it didn't work. i know that is wrong. can you please help me with my problem? thank you.
<p align="center"> <?php echo $this->table->generate();?></p></div>
<?php foreach ($tblemployee as $row){?>
<input type="text" name="empnumber" readonly="readonly" value="<?php echo $row->empnumber;?>"/>
<input type="hidden" name="empnumber" value="<?php echo $row->empnumber;?>"/>
here is my view for guide. thank you.
as Simple you can use
In Controller
$data['tblemployee'] = $this->model_name->reporttable($id)//assign your data base value to variable
$this->load->view('your view name',$data )
in Model
public function reporttable($id)
{
$query = $this->db->query("select * from tblreport where empnumber = '$id'");
$result = $query->result_array();
return $result; // this will return your data as array
}
In view
<?php
foreach ($tblemployee as $row)
{
echo $row['id];
}?>
Try this :
To make it more simplier.
In model :
public function reporttable ($id){
$this->db->select('*');
$this->db->from('tblreport');
$this->db->where('empnumber', $id);
$query = $this->db->get();
return $query->return_array(); // use this if so want to return many query if not you can also use first_row('array')
}
In controller :
public function function_name (){
$data['variable_name'] = $this->model_name->reporttable($id); // change the model_name by your own model where your function reporttable is located and use the variable_name for your view,
$this->load->view('view_name' , $data); // load the view page you want to display.
}
In Controller
$data['tblemployee'] = $this->model_name->reporttable($id)//assign your data base value to variable
$this->load->view('your view name',$data )
in Model
public function reporttable($id)
{
$query = $this->db->query("select * from tblreport where empnumber = '$id'");
$result = $query->result_array();
return $result; // this will return your data as array
}
In view
<?php
foreach ($tblemployee as $row)
{
echo $row['id];
}?>

get query results from cdbcommand Yii

I've been trying to get the results from my query for the past two hours, in my model I have this
public function getQuotes()
{
$data = Yii::app()->db->createCommand('Select fromm from city_fare_final');
$data->queryRow();
return $data ;
}
in the controller
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$model=new QuoteForm();
if(isset($_POST['QuoteForm']))
{
$model->attributes=$_POST['QuoteForm'];
if ($model->validate())
{
$priceTable=new CityFareFinal;
$priceTable->fromm=$model->pickupL;
$priceTable->too=$model->dropoffL;
$priceTable->type_of_car=$model->type;
this->render('result',array('model'=>$priceTable))
}
}
else
{
$this->render('index',array('model'=>$model));
}
}
and in the view
<div id="moduleResult">
<span><?php echo $model->getQuotes() ;?><------ Here</span>
</div>
but it always give me an error saying "Object of class CDbCommand could not be converted to string ", what can I do to get the results of my query made in the model???
Regards
Gabriel
public function getQuotes()
{
$data = Yii::app()->db->createCommand('Select fromm from city_fare_final');
$data->queryRow();
return $data ;
}
Your getQuotes() return Object of class CDbCommand:
+ You returned $data in the function instead of $data->queryRow().
By the way, you cannot use echo for array data.
The below example is used for fetching data from DB to view by using DAO with Yii: I suppose you have Person model and Person controller
In your Person model:
function getData() {
$sql = "SELECT * from Person";
$data = Yii::app()->db
->createCommand($sql)
->queryAll();
return $data;
}
In your controller:
function index(){
$data = Person::model()->getData();
$this->render('your_view',array(
'data'=>$data,
));
}
In your view: you can foreach your data to echo items in the array data:
<?php foreach($data as $row): ?>
//show something you want
<?php echo $row->name; ?>
<?php endforeach; ?>
$data->queryRow(); returns result in array format. Your code is returning $data which is an object not result of query. That's why you are getting this error.
If you want to fetch single value you can use $data->queryScalar();
In case of queryRow() your code will be
public function getQuotes()
{
$data = Yii::app()->db->createCommand('Select * from city_fare_final');
$result = $data->queryRow();
return $result ; //this will return result in array format (single row)
}
for a single field value you code will be
public function getQuotes()
{
$data = Yii::app()->db->createCommand('Select xyz from city_fare_final');
$result = $data->queryScalar();
return $result; //return single value of xyz column
}
I hope this will help.
below sample code to traverse rows returned by queryAll
$connection = Yii::app()->db;
$command = $connection->createCommand("Select * from table");
$caterow = $command->queryAll(); //executes the SQL statement and returns the all rows
foreach($caterow as $retcat )
{
echo $retcat["ColumnName"] ;
}
Returns Arrary of rows with fields
Model: Notices.php:
---------------------------------
public function getNoticesBlog($offset = 0){
$dataResult = Yii::app()->db->createCommand()->select('*')->from($this->tableName())
->andWhere("delete_flg=:delete_flg",array(':delete_flg'=>0))
->andWhere("publish=:publish",array(':publish'=>1))
->limit(3)->offset($offset)->order('created_on DESC')->queryAll();
return $dataResult;
}
Controller: NoticesController.php
$firstNotices = Notices::model()->getNoticesBlog(0);
$secondNotices = Notices::model()->getNoticesBlog(3);
$thirdNotices = Notices::model()->getNoticesBlog(6);
$this->render('Notices',array(
'firstNotices'=>$firstNotices,
'secondNotices'=>$secondNotices,
'thirdNotices'=>$thirdNotices,
)
);

Fatal error: Call to a member function num_rows() on a non-object [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
Hihow r u all?
I m trying to calculate basic salary with Particular employee_id but when i m trying to .. give me fatal error..
Fatal error: Call to a member function num_rows() on a non-object in D:\wamp\www\template\application\models\salary.php on line 112
my code is: model
<?php
class Salary extends Model
{
/*
Determines if a given person_id is a profile
*/
function exists($salary_id)
{
$this->db->from('salary_scale');
$this->db->where('id',$salary_id);
$this->db->where('deleted',0);
$query = $this->db->get();
return ($query->num_rows()==1);
}
/*
Determines if a given employee_id is a employee
*/
function exists_employee($employee_id)
{
$this->db->from('grade_history');
$this->db->where('employee_id',$employee_id);
$query = $this->db->get();
return ($query->num_rows()==1);
}
/*
Returns all the suppliers
*/
function get_all()
{
$this->db->from('salary_scale');
$this->db->where('deleted', 0);
$this->db->order_by("name", "asc");
return $this->db->get();
}
/*
*
* Gets information about a particular employees salary
*/
function grade_rules_info($salary_grade)
{
$this->db->from('salary_scale_rules');
$this->db->where('salary_grade',$salary_grade);
$query = $this->db->get();
if($query->num_rows()==1)
{
return $query->row();
}
else
{
//Get empty base parent object, as $item_id is NOT an item
$salary_obj=new stdClass();
//Get all the fields from items table
$fields = $this->db->list_fields('salary_scale_rules');
foreach ($fields as $field)
{
$salary_obj->$field='';
}
return $salary_obj;
}
}
/*
*
* Gets information about a particular employees salary
*/
function get_info($employee_id)
{
$this->db->from('allowance');
//$this->db->join('deductions', 'deductions.eid = allowance.eid');
$this->db->where('employee_id',$employee_id);
$query = $this->db->get();
if($query->num_rows()==1)
{
return $query->row();
}
else
{
//Get empty base parent object, as $item_id is NOT an item
$salary_obj=new stdClass();
//Get all the fields from items table
$fields = $this->db->list_fields('items');
foreach ($fields as $field)
{
$salary_obj->$field='';
}
return $salary_obj;
}
}
/**
* Gets information about a particular employees salary
*
**/
function get_grade_info($employee_id)
{
$this->db->from('grade_history');
$this->db->where('employee_id',$employee_id);
$query = $this->db->get();
if($query->num_rows()==1)
{
return $query->row();
}
else
{
//Get empty base parent object, as $employee_id is NOT an employee
$grade_obj=new stdClass();
//Get all the fields from items table
$fields = $this->db->list_fields('grade_history');
foreach ($fields as $field)
{
$grade_obj->$field='';
}
return $grade_obj;
}
}
/**
* Inserts or updates configuration data
*
*/
function save_grade(&$data, $employee_id=false)
{
if (!$employee_id)
{
if($this->db->insert('grade_history', $data))
{
$data['id']=$this->db->insert_id();
return true;
}
return false;
}
$this->db->where('id', $employee_id);
return $this->db->update('grade_history', $data);
}
// ------------------------ End of save_salary_cinfig function -----------------------------
/*
* Basic pay salary calculation
*/
function basic_pay($employee_id)
{
// Get grade information from grade_history table
// Get Particular person grade ifnormation by employ_id
$grade_info = $this->get_grade_info($employee_id);
$salary_grade = $grade_info->salary_grade;
$no_of_increment = $grade_info->number_of_increment;
// Get Grade rules information about particular grade by passing $salary_grade number
$grade_rules = $this->grade_rules_info($salary_grade);
$basic_amount = $grade_rules->basic_amount;
$increment = $grade_rules->increment;
$max_no_of_increment = $grade_rules->number_of_increment;
$max_amount = $grade_rules->max_amount;
return $basic_pay = $basic_amount + $increment*$no_of_increment;
}
}
?>
controller
<?php
require_once ("secure_area.php");
class Salaries extends Secure_area
{
function __construct()
{
parent::__construct('salaries');
}
function index()
{
$data['controller_name']=strtolower($this->uri->segment(1));
$data['form_width']=$this->get_form_width();
$data['manage_table']=get_profile_manage_table($this->Profile->get_all(),$this);
$this->load->view('salaries/manage',$data);
}
/*
Returns profile table data rows. This will be called with AJAX.
*/
function search()
{
$search=$this->input->post('search');
$data_rows=get_profile_manage_table_data_rows($this->Profile->search($search),$this);
echo $data_rows;
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest()
{
$suggestions = $this->Profile->get_search_suggestions($this->input->post('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
}
/*
Loads the profile form
*/
function view($employee_id=-1)
{
//$data['salary_summary_info'] =$this->Salary->get_info($salary_id);
//$data['salary_deductions_summary_info'] =$this->Salary->get_deductions_info($salary_id);
$employee_id = array('' => '-- Select Employee ID --');
foreach($this->Profile->get_employee_id()->result_array() as $row)
{
$employee_id[$row['employee_id']]= $row['employee_id'];
}
$data['employee_id'] = $employee_id;
// $data['selected_employee_id'] = $this->Profile->get_info($employee_id)->employee_id;
$data['basic_pay'] = $this->Salary->basic_pay($employee_id);
$this->load->view("salaries/salary_summary_form", $data);
}
//--------------------------------------End view function-----------------------------------
/*
Loads the profile form
*/
function grade_view($employee_id=-1)
{
$data['salary_grade_info'] = $this->Salary->get_grade_info($employee_id);
$data['basic_pay'] = $this->Salary->basic_pay($employee_id);
$this->load->view("salaries/grade_view", $data);
}
//--------------------------------------End view function-----------------------------------
/*
Inserts/updates a profile
*/
function save_salary_grade($id=-1)
{
$grade_data = array(
'eid' =>$this->input->post('employee_id'),
'salary_grade' =>$this->input->post('salary_grade'),
'number_of_increment' =>$this->input->post('number_of_increment'),
'comments' =>$this->input->post('comments'),
'date' =>date('Y-m-d H:i:s')
);
if($this->Salary->save_grade($grade_data, $id))
{ //New profile
if($id==-1)
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('profiles_successful_adding').' '.
$grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=>$grade_data['eid']));
}
else //previous profile
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('profiles_successful_updating').' '.
$grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=>$grade_data['eid']));
}
}
else//failure
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('profiles_error_adding_updating').' '.
$grade_data['salary_grade'].' '.$grade_data['number_of_increment'],'id'=>$grade_data['id']));
}
}
/*
This deletes profiles from the profiles table
*/
function delete()
{
$profiles_to_delete=$this->input->post('ids');
if($this->Profile->delete_list($profiles_to_delete))
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('profiles_successful_deleted').' '.
count($profiles_to_delete).' '.$this->lang->line('profiles_one_or_multiple')));
}
else
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('profiles_cannot_be_deleted')));
}
}
/*
get the width for the add/edit form
*/
function get_form_width()
{
return 900;
}
}
?>
and view
<?php
echo form_open('salaries/save/'.$employee_id, array('id'=>'salary_summary_form'));
//echo form_open('salaries/save/', array('id'=>'salary_summary_form'));
?>
<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<fieldset id="salary_allowance_info">
<legend><?php echo $this->lang->line("salaries_allowance_info"); ?></legend>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('salaries_employee_id').':', 'employee_id', array('class'=>'required')); ?>
<div class='form_field'>
<?php echo form_dropdown('employee_id', $employee_id);?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('salaries_allowance_basic_salary').':', 'basic_salary', array('class'=>'required')); ?>
<div class='form_field'>
<?php echo form_input(array(
'name'=>'basic_salary',
'id'=>'basic_salary',
'value'=>$basic_pay
));
?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('salaries_allowance_house_rent').':', 'house_rent',array('class'=>'required')); ?>
<div class='form_field'>
<?php echo form_input(array(
'name'=>'house_rent',
'id'=>'house_rent',
// 'value'=>$salary_summary_info->house_rent
));
?>
</div>
</div>
<?php
echo form_submit(array(
'name'=>'submit',
'id'=>'submit',
'value'=>$this->lang->line('common_submit'),
'class'=>'submit_button float_right')
);
?>
</fieldset>
<?php
echo form_close();
?>
pls help me if any one
You don't test if your call to $db -> get() succeeded. I don't know the details of your $db class, but I suspect it only returns something if the call to it was successful. If the query fails does $db -> get() still return something?
Try doing a var_dump on what you get out of $db -> get() so you can see if it's returning what you think it's returning.
Fatal error: Call to a member function num_rows() on a non-object... is usually because there were no results return from a given query or possibly from a bad query.

Categories