Order text of database result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

stijn22
Forum Commoner
Posts: 43
Joined: Sat Aug 13, 2011 10:14 am

Re: Order text of database result

Post by stijn22 »

From my free test webhost: PHP version 5.2.* :( So, is there an other solution?
stijn22
Forum Commoner
Posts: 43
Joined: Sat Aug 13, 2011 10:14 am

Re: Order text of database result

Post by stijn22 »

Nobody knows? I need it as fast as possible.
stijn22
Forum Commoner
Posts: 43
Joined: Sat Aug 13, 2011 10:14 am

Re: Order text of database result

Post by stijn22 »

Can't it be done with substrings?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Order text of database result

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
stijn22
Forum Commoner
Posts: 43
Joined: Sat Aug 13, 2011 10:14 am

Re: Order text of database result

Post by stijn22 »

I can see that it outputs this:
[year] => 2006
[month] => 12
[day] => 12

But that is not exactly what I want, can I modify that?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Order text of database result

Post by VladSun »

stijn22 wrote:I can see that it outputs this:
[year] => 2006
[month] => 12
[day] => 12

But that is not exactly what I want, can I modify that?
Yes, you can.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Order text of database result

Post by pickle »

strtotime() understands MySQL's date format, so this will work:

Code: Select all

$date = date('d-m-Y',strtotime($list->datum));
I also support the opinion of leaving the field as the DATE type. You can convert to a UNIX timestamp either with PHP's strtotime(), or MySQL's UNIX_TIMESTAMP() function, if you need a timestamp. The DATE type is much more readable if you're ever in the database manually.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
stijn22
Forum Commoner
Posts: 43
Joined: Sat Aug 13, 2011 10:14 am

Re: Order text of database result

Post by stijn22 »

Thanks! It's is now working :D

I also want to leave the field DATE type, since I can easely sort them by ASC when the field is DATE.

Thanks again all of you, I've learned some great new php stuff :)
Post Reply