• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The wonders of order_by

#1
I just discovered this and it is wonderful. I hope it is not dangerous/wrong or ill advised. Thought I would mention it and perhaps suggest the documentation should mention it, as it is very handy to know.

I had an online shop where I wanted to order the sale items by the amount saved, i.e. product price minus sale price. I was struggling for a while on how to do this when I had an idea to try this - and it worked perfectly.

Code:
$this->db->order_by('product_price - product_sale_price', 'DESC');

The wonders of codeigniter, one line did it all.

I was about to change the admin adding of sale price to add in a column on the product table for saving amount, which would have been a pain.

I am personally very happy with this! Thank you CI for being so perfect!  Smile

Best wishes,

Paul.
Reply


Messages In This Thread
The wonders of order_by - by PaulD - 08-30-2015, 12:42 AM
RE: The wonders of order_by - by CroNiX - 08-30-2015, 08:41 AM
RE: The wonders of order_by - by PaulD - 08-31-2015, 02:51 AM
RE: The wonders of order_by - by Narf - 09-01-2015, 02:50 AM
RE: The wonders of order_by - by PaulD - 09-01-2015, 03:27 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.