Здравствуйте, я стажируюсь в компании в Бразилии, и мне нужно отсортировать это поле из таблицы, используя php codeigniter, но я не могу, потому что я очень новичок в программировании и даже больше в этой области. кто-нибудь может мне помочь?
Это модель, которую использует компания.
ps: извините за плохой engli sh и название переменных.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Model_courses extends MY_Model {
private $primary_key = 'ID_course';
private $table_name = 'courses';
private $field_search = ['NAME_course', 'IMG_course'];
public function __construct()
{
$config = array(
'primary_key' => $this->primary_key,
'table_name' => $this->table_name,
'field_search' => $this->field_search,
);
$ordem = sort($config.$field_search.$NAME_course);
parent::__construct($config);
}
public function count_all($q = null, $field = null)
{
$iterasi = 1;
$num = count($this->field_search);
$where = NULL;
$q = $this->scurity($q);
$field = $this->scurity($field);
if (empty($field)) {
foreach ($this->field_search as $field) {
if ($iterasi == 1) {
$where .= "courses.".$field . " LIKE '%" . $q . "%' ";
} else {
$where .= "OR " . "courses.".$field . " LIKE '%" . $q . "%' ";
}
$iterasi++;
}
$where = '('.$where.')';
} else {
$where .= "(" . "courses.".$field . " LIKE '%" . $q . "%' )";
}
$this->join_avaiable()->filter_avaiable();
$this->db->where($where);
$query = $this->db->get($this->table_name);
return $query->num_rows();
}
public function get($q = null, $field = null, $limit = 0, $offset = 0, $select_field = [])
{
$iterasi = 1;
$num = count($this->field_search);
$where = NULL;
$q = $this->scurity($q);
$field = $this->scurity($field);
if (empty($field)) {
foreach ($this->field_search as $field) {
if ($iterasi == 1) {
$where .= "courses.".$field . " LIKE '%" . $q . "%' ";
} else {
$where .= "OR " . "courses.".$field . " LIKE '%" . $q . "%' ";
}
$iterasi++;
}
$where = '('.$where.')';
} else {
$where .= "(" . "courses.".$field . " LIKE '%" . $q . "%' )";
}
if (is_array($select_field) AND count($select_field)) {
$this->db->select($select_field);
}
$this->join_avaiable()->filter_avaiable();
$this->db->where($where);
$this->db->limit($limit, $offset);
$this->db->order_by('courses.'.$this->primary_key, "DESC");
$query = $this->db->get($this->table_name);
return $query->result();
}
public function join_avaiable() {
$this->db->join('category_courses', 'category_courses.ABBREVIATE = courses.CATEGORY', 'LEFT');
$this->db->join('level_courses', 'level_courses.ID_LEVEL = courses.LEVEL', 'LEFT');
return $this;
}
public function filter_avaiable() {
return $this;
}
}
/* End of file Model_courses.php */
/* Location: ./application/models/Model_courses.php */