Sessions sort strange .. or rather don't!

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

not stupid!

Post by jazcyk »

I believe you because I'm stupid.
Only confused as coders are! I have 5 of them myself. Will be 8 soon :(
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

here's the sorting:

Code: Select all

	while (false !== ($dat = readdir($dir))) {
		if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
			$trackingDates[] = FileToDate($dat);
		}
	}
    
	closedir($dir);
    ksort($trackingDates);
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

to be sure ...

Post by jazcyk »

I am not quite sure where to put it!

Will you please post the complete code to replace with. :)
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

here it is:

Code: Select all

	$dir = opendir(PMF_ROOT_DIR."/data");
    $trackingDates = array();
    
	while (false !== ($dat = readdir($dir))) {
		if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
			$trackingDates[] = FileToDate($dat);
		}
	}
    
	closedir($dir);
    ksort($trackingDates);
?>
        <label class="left"><?php print $PMF_LANG["ad_stat_browse"]; ?>:</label>
		<select name="day" size="1">
<?php
    foreach ($trackingDates as $trackingDate) {
        printf('<option value="%s"', date("Y-m-d", $trackingDate));
        if (date("Y-m-d", $trackingDate) == strftime('%Y-%m-%d', time())) {
			print ' selected="selected"';
		}
		print '>';
		print date('Y-m-d', $trackingDate);
		print "</option>\n";
    }
?>
		</select><br />
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

nope!

Post by jazcyk »

still does not sort!

where is the FileToDate() function? I believe it sorts, but does not print in sorted order!
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

the FileToDate() function is located in inc/functions.php and reads the date out of the file name and returns a unix timestamp.

I'll test it more on my box.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

change the

Code: Select all

ksort($trackingDates);
to

Code: Select all

sort($trackingDates);
and it works here on my box.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

php.net

Post by jazcyk »

http://www.php.net/manual/en/function.ksort.php

example code

Code: Select all

<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort($fruits);
foreach ($fruits as $key => $val) {
   echo "$key = $val\n";
}
?> 
However this array definition is not associative:

Code: Select all

$trackingDates = array();
I think the array does not have a key!
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

Yep!

Post by jazcyk »

Now it works! :D

I think we agreed at last! ksort() does not work with this array. sort() does!

thanks!
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

okay, I will backport it to 1.5.8.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

not quite

Post by jazcyk »

the sorting in the drop-down is OK, but now it sends the wrong date for lookup. 1969-12-31 is ALWAYS sent no matter which date I select from the dropdown! I think 1970-01-01 is first date in quite a lot of computer calendar-functions (a MySQL TIMESTAMP too). This is one day just before that.

Now this code gets too hairy to me!

If it works for you then I possibly just messed up the code. Available from snapshot build?

BTW: Looks like we got ourselves an additional dropdown too!

Image
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

snapshot

Post by jazcyk »

I tried the latest snapshot, but it seems to be the file of the original 1.5.7 distribution! It sorts disorderly but sends the correct date.

:roll:
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I'm working on that problem tomorrow. I'll watch a movie now. :-)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

it's fixed with that code:

Code: Select all

	$dir = opendir(PMF_ROOT_DIR."/data");
    $trackingDates = array();
    
	while (false !== ($dat = readdir($dir))) {
		if ($dat != "." && $dat != ".." && strlen($dat) == 16 && !is_dir($dat)) {
			$trackingDates[] = FileToDate($dat);
		}
	}
    
	closedir($dir);
    sort($trackingDates);
?>
        <label class="left"><?php print $PMF_LANG["ad_stat_browse"]; ?>:</label>
		<select name="day" size="1">
<?php
    foreach ($trackingDates as $trackingDate) {
        printf('<option value="%d"', $trackingDate);
        if (date("Y-m-d", $trackingDate) == strftime('%Y-%m-%d', time())) {
			print ' selected="selected"';
		}
		print '>';
		print date('Y-m-d', $trackingDate);
		print "</option>\n";
    }
?>
		</select><br />
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
jazcyk
Posts: 385
Joined: Wed Sep 07, 2005 1:32 pm

almost

Post by jazcyk »

now sorting is OK, and it sends the correct date for lookup in the database.

But some DHTML issue with <forms>tags . We have now two drop-downs! :lol:

Image
Last edited by jazcyk on Sat Mar 04, 2006 4:30 pm, edited 1 time in total.
Post Reply