Reply to Re: Sort after adding leading zero to date?

Your name:

Reply:


Posted by GarryJones on 12/07/06 23:53

naixn skrev:

> Try to put your dates in an array, and sort this array in PHP, since the latter has so many sort functions ....

How do I do that? I need to display the data with a different colour
background on alternate rows. Currently I have this page which sorts
everything according to another field.

http://www.scfmotion.se/index15ce.php

I want to be able to sort using the date (datum) field instead.

This is the nearest I can get.... (dont know how to use arrays for
this)

First I get the data from several tables with this

(This is the code that sorts it in the wrong order as it has no leading
zeros in its raw data format from the table).

I would like resort all the data once the leading zeros have been
added, but the way I am doing it is adding the leading zero on each row
one by one and each row is processed in its original sort order which
is wrong because of the fact there are no leading zeros.

$ml_collect='SELECT * FROM ml_lopp LEFT JOIN scfmforening ON
(scfmforening.scfmnum=ml_lopp.scfmnum) LEFT JOIN ml_tidplats ON
(ml_tidplats.loppnum=ml_lopp.loppnum) ORDER BY ml_mna,ml_dya';
$ml_upg=mysql_query($ml_collect);
$num_ml=mysql_numrows($ml_upg);

// set $i to 0 and print a row "a"

$i=0;

// test to see if last row has been processed
while ($i < $num_ml){


// obtain info from the current row
$loppnmn=mysql_result($ml_upg,$i,"loppnmn");
$scfmfor=mysql_result($ml_upg,$i,"scfmfor");
$scfmnum=mysql_result($ml_upg,$i,"scfmnum");
$ml_mna=mysql_result($ml_upg,$i,"ml_mna");
$ml_dya=mysql_result($ml_upg,$i,"ml_dya");

// add a leading zero to the month if necessary
$ml_mna++;
if (strlen($ml_mna) < 2) {
$ml_mna = '0' .$ml_mna;

// add a leading zero to the day if necessary
$ml_dya++;
if (strlen($ml_dya) < 2) {
$ml_dya = '0' .$ml_dya;
$montest[$ml_mna]
}


// print with row a code

echo '<tr><td width="275" class="scfmotion_rowa">';
print $loppnmn;
echo '</td><td width="275" class="scfmotion_rowa">';
print $scfmfor;
echo '</td><td width="150" class="scfmotion_rowa">';
print "2007";
print "-";
print $ml_mna;
print "-";
print $ml_dya;
echo '</td><td width="50" class="scfmotion_rowa_right">';
print $scfmnum;
echo '</td></tr>';

// add one to $i
$i++;


// test to see if last row has been processed
while ($i < $num_ml){

// obtain info from the current row
$loppnmn=mysql_result($ml_upg,$i,"loppnmn");
$scfmfor=mysql_result($ml_upg,$i,"scfmfor");
$scfmnum=mysql_result($ml_upg,$i,"scfmnum");
$ml_mna=mysql_result($ml_upg,$i,"ml_mna");
$ml_dya=mysql_result($ml_upg,$i,"ml_dya");

// add a leading zero to the month if necessary
$ml_mna++;
if (strlen($ml_mna) < 2) {
$ml_mna = '0' .$ml_mna;


// add a leading zero to the day if necessary

$ml_dya++;
if (strlen($ml_dya) < 2) {
$ml_dya = '0' .$ml_dya;
$montest[$ml_mna]
}

// print with row b code

echo '<tr><td width="275" class="scfmotion_rowb">';
print $loppnmn;
echo '</td><td width="275" class="scfmotion_rowb">';
print $scfmfor;
echo '</td><td width="150" class="scfmotion_rowb">';
print "2007";
print "-";
print $ml_mna;
print "-";
print $ml_dya;
echo '</td><td width="50" class="scfmotion_rowb_right">';
print $scfmnum;
echo '</td></tr>';
$i++;

}
}

This loops until all rows printed, alternatly with a and b code


Any help appreciated

Garry Jones
Sweden

[Back to original 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

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