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();
// ^
}
Related
I have the following function:
public function getUserMediaAction(Request $request)
{
$data = $this->decodeToken($request);
$username = $data['email'];
$user = $this->getDoctrine()->getRepository('ApplicationSonataUserBundle:User')
->findOneBy(['email' => $username]);
$idUser = $user->getId();
$media = $this->getDoctrine()->getRepository('ApplicationSonataUserBundle:User')
->findNewbieAllData($idUser);
return new JsonResponse(['media' => $media->getPath()]);
}
findNewbieAllData:
public function findNewbieAllData($id_newbie)
{
$sql = "SELECT m
FROM ApplicationSonataUserBundle:User u
JOIN ApplicationSonataUserBundle:Media m
WHERE u.id=?1";
$query = $this->getEntityManager()
->createQuery($sql)
->setParameter(1, $id_newbie);
$result = $query->getArrayResult();
return $result;
}
which unfortunately returns the following error:
Call to a member function getPath() on array
Stack Trace
in src\CoolbirdBundle\Controller\UserController.php at line 97 -
$media = $this->getDoctrine()->getRepository('ApplicationSonataUserBundle:User')
->findNewbieAllData($idUser);
return new JsonResponse(['media' => $media->getPath()]);
}
Would anyone have any idea of how I can solve this problem, please?
thank you in advance
Try the following instead:
return new JsonResponse(['media' => $media[0]->getPath()]);
Edit: Looking at the var_dump output you should try this:
return new JsonResponse(['media' => $media[0]['path']]);
Method findNewbieAllData hydrates data with arrays.
$result = $query->getArrayResult();
return $result;
Look at getArrayResult method here:
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/AbstractQuery.php
Use getResult method instead.
I'm trying to take some values form the database and I tried the code like this
$condition = ['restaurant_id' => $restaurant_id, 'menu_category_id' => $menu_category_id, 'current_template_id' => '0'];
$this->db->select('time_range');
$this->db->from('menu_category_timing_t');
$this->db->where($condition);
$query = $this->db->get();
$data = $query->result();
if ( $data ) {
print_r("data available")
}
else {
print_r("data is not available");
}
But it showing some error as Call to a member function result() on a non-object
Instead of using $data = $query->result(); use $data = $query->result_array();
Incase if their is no value for the query, it will return an empty array. So now your if else condition will work.
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);
}
,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
My model:
public function category($column, $value)
{
$this->db->select('c.cat2, c.category, m.id, m.date, m.when_date, m.when_time, m.where_m, m.age1, m.age2, m.opis, m.rozpoznamy');
$this->db->from('category c');
$this->db->where($column, $value);
$this->db->join('meeting m', 'm.id_cat = c.id');
$result = $this->db->get();
return $result->result();
}
public function delete($where, $column, $value)
{
$this->db->delete($this->users_m->category($column, $value), $where);
}
My controler:
public function delete()
{
$cat = $this->uri->segment(3);
$value = $this->uri->segment(4);
$column = 'm.id';
$where = array('m.id' => $value);
$this->users_m->delete($where, $column, $value);
redirect('main/category/' . $cat);
}
I have problem to delete data from join table, get this message when I try delete:
A Database Error Occurred
Error Number: 1146
Table 'ci.object' doesn't exist
DELETE FROM `Object` WHERE `m`.`id` = '13'
Filename: C:\xampp\htdocs\ci\system\database\DB_driver.php
Line Number: 330
So probably theres a problem with table in function delete. I try on different ways to get to this table and I don't know how to solve this. Any clue?
You're passing a CI Object into $this->db->delete() as $this->users_m->category() returns a DB result array of object(s).
CI Delete works by passing in the table name, in your case it looks like it will be
public function delete($where) {
$this->db->where('meeting m', $where);
$this->db->delete('meeting');
}
I can't work out why you have extra values in there