I have a problem with my model. i have query like this :
SELECT a.id_stap, a.kd_stap, a.stap, b.nil_punish, b.tgl_punish FROM tbl_status a LEFT JOIN tbl_punish b ON a.id_stap = b.kd_stat_punish AND b.id_i_punish = ( SELECT max( id_i_punish ) FROM tbl_punish WHERE kd_stat_punish = a.id_stap )
and my model :
function get_list()
{
if($this->table_name === null)
return false;
$select = "{$this->table_name}.*";
$select .= ", tbl_punish.tgl_punish, tbl_punish.nil_punish";
if(!empty($this->relation))
foreach($this->relation as $relation)
{
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);
if(strstr($related_field_title,'{'))
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
else
$select .= ", $unique_join_name.$related_field_title as $unique_field_name";
if($this->field_exists($related_field_title))
$select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
}
$this->db->select($select, false);
$this->db->join('tbl_punish','tbl_punish.kd_stat_punish = '. $this->table_name . '.id_stap','left');
$this->db->group_by('kd_stap');
$results = $this->db->get($this->table_name)->result();
return $results;
}
}
how to i write a code in mymodel?:
AND b.id_i_punish = ( SELECT max( id_i_punish ) FROM tbl_punish WHERE kd_stat_punish = a.id_stap )
can any ide???
