You are here: Sort after adding leading zero to date? « PHP Programming Language « IT news, forums, messages
Sort after adding leading zero to date?

Posted by GarryJones on 12/07/06 22:14

I have code numbers in 2 fields from a table which correspond to month
and date.

(Month, Code number)
Field name = ml_mna
1
2
3
etc up to 12
(Data is entered without a leading zero)


Field name = ml_dya
(Date, Code number)
1
2
3
etc up to 31
(Data is entered without a leading zero)

I can sucessfully add a leading zero if necessary to each number after
retrieving with select using the following....

$ml_mna=mysql_result($ml_upg,$i,"ml_mna");
$ml_mna++;
if (strlen($ml_mna) < 2) {
$ml_mna = '0' .$ml_mna;
}

for the month and

$ml_dya=mysql_result($ml_upg,$i,"ml_dya");
$ml_dya++;
if (strlen($ml_dya) < 2) {
$ml_dya = '0' .$ml_dya;
}

for the day

However, I need to display the data in date order.

Using "order by" the dates are sorted before I add this leading zero
and the result is an incorrect and confusing display

For instance the date of 30 5 (30 May) is displayed in the wrong place.
(Its sorted as 1,3,4, and not 01, 04, 30).

05 01 (1st May)
05 30 (30th May)
05 04 (4th May)

So how can I sort the date after selecting, after adding the necessary
leading zeros and before displaying?

Thankfull for any help in this matter

Garry Jones
Sweden

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация