View Full Version : PHP Help Needed
Fyron
December 6th, 2003, 02:02 AM
So I am trying to spruce up my image mod mirror page... I am running into problems with trying to sort the files to be in alphabetical order (and hopefully be able to include options to sort in other methods as well). No, I am not going to write this to use a database. It does not sort properly, and I have no idea how to make it do so. Yes, there is a lot of theoretical code commented out. http://forum.shrapnelgames.com/images/icons/icon12.gif The sorting portion begins at this like:
// Sorting that doesn't work. :'S
Here is the code:
http://imagemod.spaceempires.net/indexmda.txt
And here is the script running:
http://imagemod.spaceempires.net/indexmda.php
Ruatha
December 6th, 2003, 02:38 AM
Will check now.
Edit1:
This is an included file, right.
As I get errors for missing definition of index, numitems, full etc....
Will check further..
Edit2:
Copying the script to my server and the files in the directory (to be sorted) and removing inclusions of header and footer, gives too many errors to even start debugging.
If I'll dig into I ought to have more...
I'll skip all else and just look at the sorting.
[ December 06, 2003, 00:55: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 02:53 AM
I don't get any errors about missing definitions... that, and I don't think it is necessary to explicitly define variables separately to just using them in PHP.
The file is not included in anything.
[ December 06, 2003, 00:54: Message edited by: Imperator Fyron ]
Fyron
December 6th, 2003, 02:59 AM
Note how there are no errors when it is running under a Linux environment (on the se.net server)...
Ruatha
December 6th, 2003, 03:05 AM
Ok, then I can't explain all the errors.
Anyway, this sorts the names right It seems;
http://pbw.ath.cx/sort.txt
test
http://pbw.ath.cx/sort.php
And that's kind of strange as I haven't altered anything significant.
Can it be the multiarray that messes things up??
Edit: Ahh, I run win server...
[ December 06, 2003, 01:07: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:08 AM
Sorting a normal array is not a problem. I could just call the asort() function if that were the case. The problem is in sorting a 2D array.
Ruatha
December 6th, 2003, 03:09 AM
What I've done is to define filenames[array] at the same time as Filearray in the beginning.
And started the counter at 1 instead of zero.
As this work I can't be of any help in rooting out your problem, sorry.
[ December 06, 2003, 01:10: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:10 AM
Edit: Ahh, I run win server... <font size="2" face="sans-serif, arial, verdana">Windows and Linux treat code rather differently at times. http://forum.shrapnelgames.com/images/icons/icon12.gif
Fyron
December 6th, 2003, 03:11 AM
Originally posted by Ruatha:
What I've done is to define filenames[array] at the same time as Filearray in the beginning.
And started the counter at 1 instead of zero.
As this work I can't be of any help in rooting out your problem, sorry. <font size="2" face="sans-serif, arial, verdana">That does not work, because each filename has 4 other variables that go along with it that must be kept lined up. http://forum.shrapnelgames.com/images/icons/icon9.gif
Ruatha
December 6th, 2003, 03:11 AM
Originally posted by Imperator Fyron:
Sorting a normal array is not a problem. I could just call the asort() function if that were the case. The problem is in sorting a 2D array. <font size="2" face="sans-serif, arial, verdana">Yeah, that's what I meant with Multiarray, instead of simple array, my own vocabulary I guess....
How about making a simple 1D array also with only filenamess, and then sort that and let the multiarray (2D) follow in the sorting at the same time;
Define multiarray[1..10][1..10]
filenames_only[1..10]
Sort:
If filename[1]>Filename[2]
{
max=[1]
}
loop it and sort it
{
first filename is filename[max]
first multiarray is multiarray[max]
}
?
[ December 06, 2003, 01:15: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:14 AM
Originally posted by Ruatha:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by Imperator Fyron:
Sorting a normal array is not a problem. I could just call the asort() function if that were the case. The problem is in sorting a 2D array. <font size="2" face="sans-serif, arial, verdana">Yeah, that's what I meant with Multiarray, instead of simple array, my own vocabulary I guess.... </font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">That was posted before your edit. http://forum.shrapnelgames.com/images/icons/icon12.gif
Fyron
December 6th, 2003, 03:15 AM
How about making a simple 1D array also with only filenamess, and then sort that and let the multiarray (2D) follow in the sorting at the same time; <font size="2" face="sans-serif, arial, verdana">That seems like overkill, and it seems like there should be some way to sort 2D arrays... but it is worth a shot. http://forum.shrapnelgames.com/images/icons/icon7.gif
[ December 06, 2003, 01:17: Message edited by: Imperator Fyron ]
Ruatha
December 6th, 2003, 03:16 AM
Originally posted by Imperator Fyron:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by Ruatha:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by Imperator Fyron:
Sorting a normal array is not a problem. I could just call the asort() function if that were the case. The problem is in sorting a 2D array. <font size="2" face="sans-serif, arial, verdana">Yeah, that's what I meant with Multiarray, instead of simple array, my own vocabulary I guess.... </font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">That was posted before your edit. http://forum.shrapnelgames.com/images/icons/icon12.gif </font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Sometimes a new post can be the proper choice instead of an edit I guess...
Edit:especially in a fast post thread as this, I won't edit much more..
[ December 06, 2003, 01:16: Message edited by: Ruatha ]
Ruatha
December 6th, 2003, 03:17 AM
Originally posted by Imperator Fyron:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana"> How about making a simple 1D array also with only filenamess, and then sort that and let the multiarray (2D) follow in the sorting at the same time; <font size="2" face="sans-serif, arial, verdana">That seems like overkill, and it seems like there should be some way to support 2D arrays... but it is worth a shot. http://forum.shrapnelgames.com/images/icons/icon7.gif </font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">I agree, there must be an easy way, easy if one knows it... http://forum.shrapnelgames.com/images/icons/confused.gif
Ruatha
December 6th, 2003, 03:19 AM
http://se2.php.net/array_multisort
can this be the answer?
[ December 06, 2003, 01:22: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:22 AM
Well.. that sorted them in a new order... not alphabetical though. http://forum.shrapnelgames.com/images/icons/icon9.gif
http://imagemod.spaceempires.net/indexmda.php
Maybe my selection sort is a bit off...
Looking at link now.
[ December 06, 2003, 01:22: Message edited by: Imperator Fyron ]
Ruatha
December 6th, 2003, 03:24 AM
Strange indeed!
Edit: I can't really see any logic in the sorting http://forum.shrapnelgames.com/images/icons/icon10.gif
[ December 06, 2003, 01:25: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:25 AM
Now look at it when it is using multisort... almost in order, but not quite. http://forum.shrapnelgames.com/images/icons/confused.gif
Ruatha
December 6th, 2003, 03:27 AM
I think this takes sleeping on.....
Fyron
December 6th, 2003, 03:27 AM
I fail to see a problem with this line:
array_multisort($fileArray, SORT_ASC, SORT_STRING);
Ruatha
December 6th, 2003, 03:32 AM
Can there somwhow be a character zero involved in the sorting, as I guess the string of the filename starts with character one.
So if it tried to sort with a non existant character it would get a random one??
What if you try to define that it should sort by characters 1-3 in the filenmane?
Very Wild guess!!
Ruatha
December 6th, 2003, 03:38 AM
How about case?
Transform all to lowercase first before sorting?
Edit:
array_multisort(StrToLower($fileArray));
Or rather make it to lowercase when reading in the files, as the above propably won't work.
[ December 06, 2003, 01:41: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 03:46 AM
They are all lowercase to begin with.
Ruatha
December 6th, 2003, 04:15 AM
Here is the result from running the original file you posted on my server:
http://pbw.ath.cx/sort2.php
As you can see, it sorts them right but it doesn't display the Last file.
(Ignore all the errors and skip to the bottom)
(I've downloaded all the zip files.)
So it seems to perhaps be something with linux filesystem??
[ December 06, 2003, 02:20: Message edited by: Ruatha ]
Fyron
December 6th, 2003, 06:51 AM
Could be. I think all of those errors are due to misconfigurations in your PHP files... I only used standard PHP functions and such, and did not define anything with any names given by the errors.
Ruatha
December 6th, 2003, 09:53 AM
Originally posted by Imperator Fyron:
Could be. I think all of those errors are due to misconfigurations in your PHP files... I only used standard PHP functions and such, and did not define anything with any names given by the errors. <font size="2" face="sans-serif, arial, verdana">I think it's the parameters in stristr that needs to be surrounded by quotes for the errors to disappear.
I have standrad settings for most PHP settings except file sizes and magic quotes.
[ December 06, 2003, 07:55: Message edited by: Ruatha ]
Asmala
December 6th, 2003, 09:57 AM
Originally posted by Imperator Fyron:
I fail to see a problem with this line:
array_multisort($fileArray, SORT_ASC, SORT_STRING); <font size="2" face="sans-serif, arial, verdana">You have a wrong parameter. Array_multisort requires an array, not a multi-dimensional array. You have to modify $fileArray a bit. Now it's $fileArray[$counter][0], change it to $fileArray[0][$counter]. Then you can sort it easily. For example:
array_multisort($fileArray[0], SORT_ASC, SORT_STRING);//sorts by names.
Have you noticed when you use $file = readdir($dir_handle) you get first "." and then ".." and but then real filenames.
Ruatha
December 7th, 2003, 02:56 AM
Originally posted by Asmala:
</font><blockquote><font size="1" face="sans-serif, arial, verdana">quote:</font><hr /><font size="2" face="sans-serif, arial, verdana">Originally posted by Imperator Fyron:
I fail to see a problem with this line:
array_multisort($fileArray, SORT_ASC, SORT_STRING); <font size="2" face="sans-serif, arial, verdana">You have a wrong parameter. Array_multisort requires an array, not a multi-dimensional array. You have to modify $fileArray a bit. Now it's $fileArray[$counter][0], change it to $fileArray[0][$counter]. Then you can sort it easily. For example:
array_multisort($fileArray[0], SORT_ASC, SORT_STRING);//sorts by names.
Have you noticed when you use $file = readdir($dir_handle) you get first "." and then ".." and but then real filenames. </font><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">Yep, it's the current directory "." and the directory above ".."
as in ms dos;
CD..
Asmala
December 13th, 2003, 11:23 PM
Fyron, did you get the sorting working or did you lost interest to the whole thing?
vBulletin® v3.8.1, Copyright ©2000-2025, Jelsoft Enterprises Ltd.