My Query is this I want the records order by average rating but it's not getting records in descending order
$this->db->select('doctors.* , speciality.speciality_name , avg(rating.rating) as avg_rating');
$this->db->from('doctors');
$this->db->join('speciality' , 'doctors.speciality_id = speciality.id' , 'left');
$this->db->join('rating' , 'doctors.id = rating.doctor_id' , 'left');
$this->db->group_by('doctors.id');
$this->db->order_by('avg_rating' , 'desc');
I am getting records in this order according to avg_rating
[avg_rating] => 4.0000
[avg_rating] => 4.0000
[avg_rating] => 4.5000
[avg_rating] => 3.0000
but I want 4.5 on top
View file code where I am showing this data
<ul class="selectedList">
<?php if(isset($doctors_data) && !empty($doctors_data)){ foreach($doctors_data as $result){ ?>
<li>
<div class="row noMargin">
<div class="col-lg-2 col-md-2 col-sm-6 col-xs-5 first">
<a href="<?php echo base_url(); ?>home_ctrl/detail_page?refer_id=<?php echo $result->id;?>">
<?php if(isset($result->img_name) && !empty($result->img_name)){ ?>
<img src="<?php echo base_url(); ?>includes/images/doctors/<?php echo $result->img_name; ?>" alt="Best Lady doctors" class="img-responsive doctorImg">
<?php }else{ ?>
<img src="<?php echo base_url(); ?>includes/images/doctor.jpg" alt="Best Lady doctors" class="img-responsive doctorImg">
<?php } ?>
</a>
</div>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-7 col-md-push-7 third noPadding">
<p class="text-right stars" id="<?php echo $result->id; ?>" data-rating="<?php echo round($result->avg_rating); ?>"></p>
<p><span class="fa fa-phone tdinnerSpan"></span> <?php echo $result->phone; ?></p>
<span class="fa fa-clock-o tdinnerSpan"></span><p style="width:auto !important" class="innerPara"> <?php echo $result->week_from; ?> - <?php echo $result->week_to; ?> <br> <?php echo date('h:i a', strtotime($result->opening)); ?> - <?php echo date('h:i a', strtotime($result->closing)); ?> </p>
</div>
<div class="col-lg-7 col-md-7 col-sm-12 col-xs-12 col-md-pull-3 second">
<a href="<?php echo base_url(); ?>home_ctrl/detail_page?refer_id=<?php echo $result->id;?>" class="doctorName"><?php echo $result->name; ?>, <small><?php echo $result->education; ?></small></a>
<p><span class="fa fa-certificate tdinnerSpan"></span><?php echo $result->speciality_name; ?></p>
<span class="fa fa-map-marker tdinnerSpan"></span><p class="innerPara addresPara"><?php echo $result->address; ?></p>
</div>
</div>
</li>
<?php } } ?>
</ul>