Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Sortowanie wyniku z pliku
Spyder
post
Post #1





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

Ostrzeżenie: (0%)
-----


Witam mam taki kod

  1. <?php
  2. $month = ($_GET["month"]) ? $_GET["month"] : 0 ;
  3.  
  4. $start = mktime(0,0,1,date("m")+$month, 1, date("Y"));
  5.  
  6. $end = mktime(0,0,1,date("m")+$month+1, 1, date("Y"));
  7.  
  8. $news = array();
  9.  
  10. $all_news = array();
  11.  
  12. $folder = opendir(".");
  13.  
  14. while (false !== ($file = readdir($folder))) {
  15. if (stristr($file, ".php") && !stristr($file, ".lck") && $file != "include_news.php") {
  16.  
  17. $fp = file($file);
  18.  
  19. foreach($fp as $l) {
  20.  
  21. if (stristr($l, "<!-- NewsItem -->")) {
  22.  
  23. $all_news[filemtime($file)] = $file;
  24. if(filemtime($file) >= $start && filemtime($file) < $end) {
  25.  
  26. $news[filemtime($file)] = $file;
  27. break;
  28.  
  29. }
  30.  
  31. }
  32. if (stristr($l, "<title>")) { break; }
  33.  
  34. }
  35. }
  36. }
  37. ksort($news);
  38.  
  39.  
  40.  
  41. ksort($all_news);
  42.  
  43. while($has_previous == false) {
  44.  
  45. --$previous_month;
  46. foreach($all_news as $k => $n) {
  47.  
  48. if ($k >= mktime(0,0,1,date("m")+$month+$previous_month, 1, date("Y")) && $k < mktime(0,0,1,date("m")+$month+$previous_month+1, 1, date("Y"))) {
  49.  
  50. $has_previous = true;
  51.  
  52. }
  53. }
  54. if ($previous_month < ($month - 23)) { break; }
  55.  
  56. }
  57.  
  58. $has_previous = false; $has_next = false; $previous_month = 0; $next_month = 0;
  59.  
  60. while($has_next == false) {
  61. ++$next_month;
  62.  
  63. foreach($all_news as $k => $n) {
  64.  
  65. if ($k >= mktime(0,0,1,date("m")+$month+$next_month, 1, date("Y")) && $k < mktime(0,0,1,date("m")+$month+$next_month+1, 1, date("Y"))) {
  66.  
  67. $has_next = true;
  68.  
  69. }
  70. }
  71. if ($next_month > ($month + 23)) { break; }
  72. }
  73. ?>

Kod pobiera z katalogu pliki ktore maja komentarz <!-- NewsItem --> i bierze z nich tytul i robi kategorie w menu oraz sortuje wg daty tak ze nowo dodana kategoria londuje na dole. Wszystko ok tylko jak zedytuje kategorie ktora juz zostala dodana to ona leci na dol. jak uzyje sortowania normalnego sort() to mam sortowanie wg nazwy chce dodac ze dla tych nazw ktore wskaze ma byc moje sortowanie tz maja byc na swoim stalym miejscu a nowe moga byc sortowane np wg nazwy (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 13:38