Currently I can view the list of my database and putting them as Sub-menus of my site, in the database they are ordered as smallest to highest (by ID)
this is the code I use to get the data on database:
$database_service = get_data_of('service', 'id,slug,image,title');
the ‘service’ in the code is the specific table I get data.
then creating a foreach loop to get the data in order, but I want it to show in a HIGHEST TO LOWEST order based on ID number.
so here’s a full code on how I get the data:
<ul class="classs class1 class2">
<?php
$database_service = get_data_of('service', 'id,slug,image,title');
foreach ($database_service as $item) {
?>
<li>
<a class="dropdown-item class lcass2" href="<?php echo $this->config->item('url') . 'service/' . $item->slug; ?>">
<img src="<?php echo $this->config->item('img').$item->image; ?>"
class="clas1 class2" style="max-width:25px;">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
how to do this?
2
Answers
Use
in your model, before below line
$this->db->get();
to sort data in descending order.
You can refer below link to know more about ordering in Codeigniter.
Order By Clause in Codeigniter
Use
OR you can also use this
DESC meaning descending order if want to show the result in ascending order just use
Check out the documentation
Check out the Tutorial