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);
}
Related
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.
developing a search module with different parameter supplied with form.
And Controller is like that
public function searchCourse()
{
$cat_id = $this->input->post('searchkey');
$course_id = $this->input->post('searchkey_course');
//$start_date = date('Y-m-d',strtotime($this->input->post('fromDate')));
$course_name = $this->input->post('searchbyname');
$university_id = $this->session->userdata('university_id');
$data['course'] = $this->crud_model->getcourseSearch($university_id, $course_id, $course_name);
$data['page_title'] = 'My Course';
$this->load->view('frontend/university/mycourse', $data);
}
Model:
public function getcourseSearch($param1 = '', $param2 = false, $param4= false)
{
$this->db->select('*');
$this->db->where('coursep_id', $param1);
if($param2){
$this->db->like('name_of_course', $param2);
}
if($param4){
$this->db->or_like('name_of_course', $param4, 'both');
}
$query=$this->db->get("course");
return $query->result();
}
The problem:
The problem is first time view is loading with list of data. which is fine but when form being submitted with search params views are being stacked with different result data. how can i overcome this.
When you are calling this function in model, you are passing three parameters $university_id, $course_id, $course_name.
so $param1= university_id, $param2=course_id and $param4=course_name.
use proper parameter while formatting query.
Like:
public function getcourseSearch($param1 = '', $param2 = false, $param4= false)
{
$this->db->select('*');
$this->db->where('coursep_id', $param2);
if($param2){
$this->db->like('name_of_course', $param4);
}
$query=$this->db->get("course");
return $query->result();
}
Hey i am novice in CI so please forgive! I am trying to join 2 tables in codeigniter and i am getting here these error in my code
Call to undefined method CI_DB_mysql_driver::row_array() in
C:\xampp\htdocs\Hostel\application\models\payfees.php on line 16.
My Code for the method is here like these
public function payu($id,$month){
$where = "where generatebills.student_id='".$id."' and generatebills.month='".$month."'";
$query = $this->db->select('*')
->from('generatebills')
->join('student','student.student_id=generatebills.student_id')
->where($where);
return $query->row_array();
}
Don't forget the missing ->get() method. Plus, remove the WHERE in the string:
$where = "name='Joe' AND status='boss' OR status='active'";
http://www.codeigniter.com/userguide2/database/active_record.html
I'd suggest use an array instead:
public function payu($id,$month)
{
// $where = "generatebills.student_id='".$id."' and generatebills.month='".$month."'";
$where = array(
'generatebills.student_id' => $id,
'generatebills.month' => $month,
);
$query = $this->db->select('generatebills.*')
->from('generatebills')
->join('student','student.student_id = generatebills.student_id')
->where($where);
return $query->get()->row_array();
// ^
}
,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
When I try to save an item in Laravel it says the following.
Call to undefined method Illuminate\Database\Query\Builder::save()
I have followed the documentation, and i can delete items fine just not update. Is there anything wrong with my code?
public function publishedMain($id, $state){
$userId = Auth::user()->id;
$userAdmin = Auth::user()->admin;
if($userAdmin == "0"){
$clients = Clients::whereRaw('id = ? and parent = ?', array($id, $state));
$clients->active = $state;
$clients->save();
die('not admin');
}else{
$clients = Clients::whereRaw('id = ?', array($id));
$clients->active = $state;
$clients->save();
die('admin');
}
}
Many Thanks
Brent
You call the save() method on the query builder, not on your model.
You're missing the ->first() piece:
$clients = Clients::whereRaw('id = ? and parent = ?', array($id, $state))->first();
Of course, this will get the first client, so naming the variable $clients makes not much sense.
You shall also check if your $clients variable is not null, in which case it didn't find anything.
(btw, your model should be called Client, not Clients)