thewooleymammoth Posted September 24, 2008 Share Posted September 24, 2008 can anyone tell me why this isnt working???? tried it on wamp and server and for some reason the natcasesort() is just sorting it like sort() would <?php $dir=$_GET['dir']; $img= scandir("$dir/"); natcasesort($img); $num=2; echo"<center><table align='top' BGCOLOR='#CCCC99' cellspacing='60'><tr valign='top'><td>"; while ($img[$num]!= null) { echo "<a href='display.php?num=$num&dir=$dir'>$img[$num]</a><br>"; if ($num2 >= 1500) { echo "</td><td>"; $num2=0; } $num2++; $num++; } ?> ive got a link to it on my server http://fatalinjury.org/list.php?dir=pics notice lowercase letters start about half way down the list Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/ Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 <?php include('menu.php'); $dir=$_GET['dir']; $img= scandir("$dir/"); natcasesort($img); $num=2; $num2=0; echo"<center><table align='top' BGCOLOR='#CCCC99' cellspacing='60'><tr valign='top'><td>"; while ($img[$num]!= null) { echo "<a href='display.php?num=$num&dir=$dir'>$img[$num]</a><br>"; if ($num2 >= 1500) { echo "</td><td>"; $num2=0; } $num2++; $num++; } echo "</tr></td></table></center>"; ?> sorry there is the right code Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649211 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2008 Share Posted September 24, 2008 The keys of the array are not changed, so when you iterate using an incrementing key, you get the original array order. I recommend using a foreach() loop instead of using the $num counter in a while loop. Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649220 Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 hmm well i dont really understand why using a foreach loop worked better than the other way but it works with a foreach loop haha thanks a million been rippin my hair out Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649224 Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 since ive fixed this problem, the scardir adds in . and .. for the first two pieces of the array, how do i get rid of that? Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649225 Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 The keys of the array are not changed, so when you iterate using an incrementing key, you get the original array order. I recommend using a foreach() loop instead of using the $num counter in a while loop. why wouldnt it be changing the order of the keys? Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649229 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2008 Share Posted September 24, 2008 You should probably read the php manual page for the function you are using to learn what the function does and does not do. Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649360 Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 You should probably read the php manual page for the function you are using to learn what the function does and does not do. i realize it doesn't change the keys, but why doesnt it? is there an advantage to keeping the keys? and also is there an alternative to make it so it does change the keys cause my site runs on the basis that the keys will line up Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649700 Share on other sites More sharing options...
thewooleymammoth Posted September 24, 2008 Author Share Posted September 24, 2008 You should probably read the php manual page for the function you are using to learn what the function does and does not do. i realize it doesn't change the keys, but why doesnt it? is there an advantage to keeping the keys? and also is there an alternative to make it so it does change the keys cause my site runs on the basis that the keys will line up after a while of reading through the comments on http://www.php.net/natcasesort if found a comment about array_values() which solved my problem thanks for the help though Link to comment https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/#findComment-649704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.