Bob Norris Posted March 3, 2013 Share Posted March 3, 2013 Hello, Im new to php and have a form I would like to have sort from newest to oldest. Could someone look at this code for me and offer some help? And if you need the link to the form online e send me a PM. Thanks in advance! http://pastebin.com/v9ExCUxc Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/ Share on other sites More sharing options...
teynon Posted March 3, 2013 Share Posted March 3, 2013 You should include more detail such as what it's doing instead of what you expected it to do. Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/#findComment-1416236 Share on other sites More sharing options...
AyKay47 Posted March 3, 2013 Share Posted March 3, 2013 (edited) STOP A couple things on the loadfile() function: 1. Using the global keyword is very bad practice as it causes scope pollution and defeats the purpose of using a function to begin with (bad times). You should be passing any information needed by the function via the functions parameter list. 2. Instead of initializing 5 arrays and storing values in each, you should be building a muti-dimensional array instead. This will make it cleaner and much easier to sort further down in the code. 3. split() is deprecated and should no longer be used, use preg_split instead. I'm sure there are more errors further down but lets start there for now. Also, it would be helpful if you posted any errors that are being displayed. Edited March 3, 2013 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/#findComment-1416249 Share on other sites More sharing options...
Bob Norris Posted March 3, 2013 Author Share Posted March 3, 2013 STOP A couple things on the loadfile() function: 1. Using the global keyword is very bad practice as it causes scope pollution and defeats the purpose of using a function to begin with (bad times). You should be passing any information needed by the function via the functions parameter list. 2. Instead of initializing 5 arrays and storing values in each, you should be building a muti-dimensional array instead. This will make it cleaner and much easier to sort further down in the code. 3. split() is deprecated and should no longer be used, use preg_split instead. I'm sure there are more errors further down but lets start there for now. Also, it would be helpful if you posted any errors that are being displayed. Appreciate it Im just in over my head. There are a couple of other files in the script I thought it might be an easy catch for you wizzes. There is function PHP that is pretty short and it may be in there. <?php function DateCmp($a, $b) { if (strtotime($a) == strtotime($b)) { return 0; } return (strtotime($a) < strtotime($b)) ? -1 : 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/#findComment-1416265 Share on other sites More sharing options...
teynon Posted March 3, 2013 Share Posted March 3, 2013 <?php function DateCmp($a, $b) { if (strtotime($a) == strtotime($b)) { return 0; } return (strtotime($a) < strtotime($b)) ? -1 : 1; } ?> Make sure to wrap your code in code blocks ("<>" Button) Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/#findComment-1416267 Share on other sites More sharing options...
Barand Posted March 4, 2013 Share Posted March 4, 2013 All you need is function DateCmp ($a, $b ) { return strtotime($a) - strtotime($b ); } Quote Link to comment https://forums.phpfreaks.com/topic/275179-difficulty-sorting/#findComment-1416349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.