A programmer kept insisting to em it's best to sort in the mysql query than to use such things as ksort, krsort, etc... in the php. Yet I see in Invision's new software they contiunue to do some sorting with php rather than the query.
Any thoughts? I got rid of all my php sorting and then see others do it and wonder if I just wasted time.
I had some other question and forgot. Blah.
Sorting In PHP vs. DB
Started by BASHERS33, Jul 30 2009 11:35 PM
4 replies to this topic
#1
Posted 30 July 2009 - 11:35 PM
|
|
|
#2
Posted 30 July 2009 - 11:42 PM
Databases are best for information handling, even as in sorting, I would not say anything else. it's part of what it is made to do. I'd avoid sortings in php if I could, but at times, maybe the database won't do, maybe you want to modify your data and then sort, or similar, and therefore need to sort by php...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#3
Posted 31 July 2009 - 04:47 AM
Yes sorting in a DB is extremly handy, if you are just modifying a number you can even do that in sql. I remember making a ranking algorithm that would use things like hits, creation date, ratings, and a few other things, using sql I got it to have a ranking value and sort by that.
Even if you do not consider speed tho, its really sloppy to add extra code to sort things.
Even if you do not consider speed tho, its really sloppy to add extra code to sort things.
#4
Posted 31 July 2009 - 07:15 AM
I would do the sorting in the DB. Some DB's will do an implicit sort based on the primary key if you don't explicitly sort, so you can end up wasting computing resources by effectively "double sorting", once in the DB, and then once in PHP.
Big projects don't always do a good job of following best-practices in all areas.
Big projects don't always do a good job of following best-practices in all areas.
#5
Posted 31 July 2009 - 08:35 AM
ok, thanks. I have it currently sorting in the DB in almost every case. I think there was one case where it just needed to be done in the php due to some data modifying, but that's it... one case.
In the IPB forum software I saw a place where he query was run and then immediately it was sorted. So not sure why they did that. There was no manipulation or anything and it was a simple krsort so why they didn;'t just order by the key descending I don't know.
In the IPB forum software I saw a place where he query was run and then immediately it was sorted. So not sure why they did that. There was no manipulation or anything and it was a simple krsort so why they didn;'t just order by the key descending I don't know.


Sign In
Create Account


Back to top










