is any one good enough to help get this working? - codeigniter

I have four tables I need to join in query build
function get_debtors( ) {
$this->db->select('invoice.student_id as STUDENT_ID,student.name AS
STUDENT_NAME,section.name AS CLASS,
invoice.description AS DESCRIPTION,
invoice.amount AS TOTAL_AMOUNT,
invoice.amount_owed AS AMOUNT_OWED,
parent.name AS PARENT_NAME,
parent.email AS PARENT_EMAIL,
parent.phone AS PARENT_PHONE,
parent.address AS PARENT_ADDRESS,
invoice.status AS STATUS');
$this->db->from('invoice , student , parent , section ');
$this->db->join('student ', 'student.student_id = invoice.student_id');
$this->db->join('parent ', 'parent.parent_id = student.parent_id, 'left'');
$this->db->join('section ', 'section.section_id = student.section_id','left');
$this->db->where('invoice.status', 'debtor');
$query = $this->db->get();

Try this. If there is still any error than post the error also here.
function get_debtors( )
{
$this->db->select('invoice.student_id as STUDENT_ID,student.name AS
STUDENT_NAME,section.name AS CLASS,
invoice.description AS DESCRIPTION,
invoice.amount AS TOTAL_AMOUNT,
invoice.amount_owed AS AMOUNT_OWED,
parent.name AS PARENT_NAME,
parent.email AS PARENT_EMAIL,
parent.phone AS PARENT_PHONE,
parent.address AS PARENT_ADDRESS,
invoice.status AS STATUS');
$this->db->from('invoice');
$this->db->join('student ', 'student.student_id = invoice.student_id');
$this->db->join('parent ', 'parent.parent_id = student.parent_id', 'left');
$this->db->join('section ', 'section.section_id = student.section_id','left');
$this->db->where('invoice.status', 'debtor');
$query = $this->db->get();
}

Related

Fetch data from a 2 many to many table

I am using codeigniter activerecord and I am fetching information of 2 many to many table but undefined index is appearing in my error log in the CI view
public function editCommission($data){
$this->db->select('client_user_cashin.id, client.account_name, property.property_name, client.unit_number, client.reservation_date, users.givenname, users.surname, client_user.sl_rate, sl_position.position, cash_in.cash_recieved, comm_status.comm_status, computation_type.com_type');
$this->db->from('client_user_cashin');
$this->db->join('client_user', 'client_user.id = client_user_cashin.client_user_id');
$this->db->join('client', 'client.id = client_user.client_id');
$this->db->join('property_commision', 'property_commision.id = client.property_commision_id');
$this->db->join('property', 'property.id = client.property_id');
$this->db->join('users', 'users.id = client_user.user_id');
$this->db->join('sl_position', 'sl_position.id = client_user.sl_position_id');
$this->db->join('cash_in', 'cash_in.id = client_user_cashin.cash_in_id');
$this->db->join('comm_status', 'comm_status.id = client_user_cashin.comm_status_id');
$this->db->join('computation_type', 'computation_type.id = cash_in.comp_type_id');
$this->db->order_by('client_user_cashin.id');
$query = $this->db->get();
return $query->result_array();
}
Fetch the data in the edit form
Just apply left-join on all the joins like
$this->db->join('client_user', 'client_user.id = client_user_cashin.client_user_id','left');

How to call information from one model to another Codeigniter

I'm stuck on this from a while.Can't figured it out.I reed documantion, tried with several videos and tried like 10 different ways, nothing is working yet.So I have one view/model for one thing, in this example Destination and I have separate files for Offers.The controllers for both are in one file.I want tho the information that is in destination to go to Offers as well.Please help I can't figure out what I'm missing:
So here is the most important parts:
destination_model.php
<?php class Destination_model extends CI_Model
{
public function getDestinationDetails($slug) {
$this->db->select('
id,
title,
information
');
$this->db->where('slug', $slug);
$query = $this->db->get('destinations')->row();
if(count($query) > 0)
{
return $query;
}
else
{
// redirect(base_url());
}
}
public function getOffersByDestination($destination_id)
{
$this->db->select('
o.short_title,
o.price,
o.currency,
o.information,
o.long_title_slug,
oi.image,
c.slug as parent_category
');
$this->db->from('offers o');
$this->db->join('offers_images oi', 'oi.offer_id = o.id', 'left');
$this->db->join('categories c', 'c.id = o.category');
$this->db->group_by('o.id');
$this->db->where('o.destination', $destination_id);
$this->db->where('o.active', '1');
return $this->db->get();
} }
And then in the controller for offers I put this:
$this->load->model('frontend/destination_model');
$this->params['destination'] = $this->destination_model->getOffersByDestination($data->id);
All I need is the title and the information about the destination.
Here is the whole controller for the offers:
$data = $this->slugs_model->getOfferDetails(strtok($this->uri->segment(2), "."));
$this->load->model('frontend/offers_model');
$this->load->model('frontend/destination_model');
$this->params['main'] = 'frontend/pages/offer_details';
$this->params['title'] = $data->long_title;
$this->params['breadcumb'] = $this->slugs_model->getSlugName($this->uri->segment(1));
$this->params['data'] = $data;
$this->params['images'] = $this->slugs_model->getOfferImages($data->id);
$this->params['similar'] = $this->slugs_model->getSimilarOffers($data->category, $data->id);
$this->params['destination'] = $this->destination_model->getOffersByDestination($data->id);
$this->params['offers'] = $this->offers_model->getImportantOffers($data->offers, $data->category, $data->id);
You need to generate query results after you get it from model,
e.g: row_array(), this function returns a single result row.
here's the doc: Generating Query Results
try this:
$this->load->model('frontend/destination_model');
$data['destination'] = $this->destination_model->getOffersByDestination($data->id)->row_array();
$this->load->view('view_name', $data);
And in your view echo $destination['attribut_name'];,
or you can print the array, to see if it's work print_r($destination);

Codeigniter - prevent added space on the select statement

How to prevent auto fix in the select statement using CodeIgniter 3?
Query that I want: SELECT REPLACE(item, ',', '') AS item (without space)
I tried : $this->db->select("replace(item, ',', '') AS item", FALSE);
Result : SELECT REPLACE(item, ', ', '') AS item (CI added a space in my query)
I read this documentation but it didn't work.
This my real query:
$this->db->select("a.unit_id");
$this->db->select("replace(c.topik, ',', '') AS topik", FALSE); //this my problem (added space which shouldnt)
$this->db->select("COUNT(*) AS jumlah");
$this->db->from('opub_kliping a');
$this->db->join('opub_media b','a.media_id = b.organisasi_id');
$this->db->join('opub_tag c','a.id = c.kliping_id');
if(!empty($data['keyword']))$this->db->where("(a.judul LIKE '%".$data['keyword']."%' OR a.text LIKE '%".$data['keyword']."')");
if(!empty($data['tgl1']))$this->db->where("a.tanggal >=",$data['tgl1']);
if(!empty($data['tgl2']))$this->db->where("a.tanggal <=",$data['tgl2']);
if(!empty($data['unit']))$this->db->where("a.unit_id ",$data['unit']);
if(!empty($data['media']))$this->db->where("a.media_id ",$data['media']);
if(!empty($data['jenis']))$this->db->where("a.jenis_id ",$data['jenis']);
if(!empty($data['tone']))$this->db->where("a.karakter ",$data['tone']);
if(!empty($data['topik']))
{
$qTopik = array();
$expTopik = explode(',', $data['topik']);
foreach($expTopik as $t)
{
if(!empty($t))
{
$qTopik[] = "c.topik LIKE '%$t%'";
}
}
if(!empty($qTopik))
{
$qTopiks = implode(",", $qTopik);
$this->db->where($qTopiks);
}
}
$this->db->where('a.unit_id !=', 0);
$this->db->where('c.topik !=', NULL);
$this->db->where('c.topik !=', '');
$this->db->group_by("a.unit_id");
$this->db->group_by("replace(c.topik, ',', '')", FALSE); //this produce correct query (without adding space)
$this->db->order_by('a.unit_id', 'ASC');
$this->db->order_by('jumlah', 'DESC');
$q= $this->db->get();
i found this after tried some experiment
$this->db->select(array('REPLACE(c.topik', "','", "'') AS topik"), false);
seems little hack maybe. but its work for me
hope will help others
change 4 lines of your query
$this->db->select("a.unit_id,replace(c.topik, ',', '') AS topik,COUNT(*) AS jumlah")->from('opub_kliping a');
$this->db->join('opub_media b','a.media_id = b.organisasi_id');

Looking for case-insensitive in Phalcon Datatables Library (m1ome)

I use this Library :
https://github.com/m1ome/phalcon-datatables
This is how i use it :
$resultset = $this->modelsManager
->createQuery("SELECT protId, protUsmsName, protUsmsId, protComsName, protAddress, protQty, protPrice, protTotalPrice,
protShpmName, protDateOrder , protPthdId
FROM ProductOrderTransaction WHERE AuditDelete = 'N' AND protMomsId = '4'
ORDER BY protId DESC")
->execute();
$dataTables = new DataTable();
$dataTables->fromResultSet($resultset)->sendResponse();
But, while i search "company" in the Data tables, it can't be found because it has value "Company". Case sensitive case.
Anyone had the modify Lib? thx
$check = (strpos(strtoupper( $item->$column ), strtoupper( $search ) ) !== false);

Display two columns as one

I wanted to select two columns and display it as one in my controller. Here is the code I currently have:
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select('dbo_students.StudentID' , 'dbo_students.FirstName AS sFname' , 'dbo_students.LastName AS sLname')
->get();
}
Any ideas on how I can combine the dbo_students.FirstName and dbo_students.LastName into one column?
You should try DB::raw. Try replacing the code in select as
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
And your final code will be
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
->get();
}

Resources