Hello i am having some trouble figuring out how to add order by on my get statement. What i want is to add order by so when i print them to have them ordered.
This is what i have tried but no results
$kasses = $this->db->from($this->kasses);
$kasses = $this->db->order_by("color", "asc");
$kasses = $query = $this->db->get();
return $kasses = $query->result();
here is where i get the database
$kasses = $this->db->get('kasses')->result_array();
and here i print it on screen
$kassa='';
foreach($kasses as $kass){
if($kass['stock_alert']>=$kass['stock']){
?>
<a href='#' onclick='showAjaxModal("index.php?modal/popup/kasses_edit/<?=$kass['id'];?>");'>
<?php echo $kass['type']." / ".$kass['color']." / ".$kass['dimensions']."cm : <span style='color:brown;font-weight:bold'>".$kass['stock']."</span></a><br/>";
}
Any idea how may i achieve that ? Thanks in advance
I figure it out this is how i did it
$this->db->order_by("color_id", "desc");
$kasses = $this->db->get('kasses')->result_array();
Try this,
$this->db->from('kasses');
$this->db->order_by('color_id','desc');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
//$kasses = $query->result_array();
}else{
return array();
}