Вы не зашли.
Главная » PHP » Сортировка
#1. DjBoBaH Off (-1)
Участник
2008.11.10 04:04
Переделываю один скриптег и мне нужна помощь с сортировкой,сейчас объясню принцип работы скрипта...
Есть 3 файла:
in.php , out.php , index.php
И 2 папки: in , out
Перейдя по ссыли in.php?site=http://test.ru в папке in создаётся файл test.ru.txt ,в который в дальнейшем будет записываться число переходов по ссыли выше.
У файла out.php принцип работы точно такой же,ток записывает он в свою папку out всё это дело. . .
Вот код файла index.php
Код:
span style="color: #0000BB"><?phpinclude"../temp/header.php";require_once"../temp/inc_online.php";$onl_c->add('в партнёрах и друзьях ФейсWAPа');echo'<div class="a">Партнёры и друзья ФейсWAPа</div>';$conf["items_per_page"] = 20;if (!isset($page)) {$page = 0;}$total = 0;if(!($dp = opendir("in/"))) die ("Cannot open ./");$file_array = array();while ($file = readdir ($dp)){if(substr($file,0,1) != '.' and $file != "index.php"){$file_array[] = $file;}}$file_count = count ($file_array);sort ($file_array);if ($file_count > 0){$first_record = $page * $conf["items_per_page"];$last_record = $first_record + $conf["items_per_page"];while (list($fileIndexValue, $file_name) = each ($file_array)){if (($fileIndexValue >= $first_record) AND ($fileIndexValue < $last_record)){$countin = @file_get_contents("in/$file_name");$countout = @file_get_contents("out/$file_name");if(!$countout){$countout=0;}$file_name = explode('.txt',$file_name);echo'<div class="b">'.$file_name[0].' ['.$countin.'/'.$countout.']<a href="out.php?site=http://'.$file_name[0].'">»</a></div>';}}if (($file_count > 0) AND ($page != 0)){$prev_page = $page -1;echo'<br/><a href="'.$_SERVER['PHP_SELF'].'?page='.$prev_page.'">назад</a><br/>';}if (($file_count > 0) AND ($last_record < $file_count)){$next_page = $page + 1;echo'<br/><a href="'.$_SERVER['PHP_SELF'].'?page='.$next_page.'">далее</a><br/>';}echo'<br/>Друзей/Партнёров: '.$file_count.'<br/>';echo'<a href="../index.php">На главную</a>';}closedir($dp);include"../temp/footer.php";?>
Мне нужно както сделать вывод сайтов в порядке убывания $countin ...
Отредактировано DjBoBaH (2008.11.10 05:05)
#2. Gemorroj Off (107)
Administrator
2008.11.10 12:12
Код:
span style="color: #0000BB"><?phpinclude"../temp/header.php";require_once"../temp/inc_online.php";$onl_c->add('в партнёрах и друзьях ФейсWAPа');echo'<div class="a">Партнёры и друзья ФейсWAPа</div>';$array = array();$conf["items_per_page"] = 20;if (!isset($page)) {$page = 0;}$total = 0;if(!($dp = opendir("in/"))) die ("Cannot open ./");$file_array = array();while ($file = readdir ($dp)){if(substr($file,0,1) != '.' and $file != "index.php"){$file_array[] = $file;}}$file_count = sizeof($file_array);sort($file_array);if($file_count > 0){$first_record = $page * $conf["items_per_page"];$last_record = $first_record + $conf["items_per_page"];for($i=0; $i<$file_count; ++$i){if(($i >= $first_record) AND ($i < $last_record)){$count_in = (int)file_get_contents('in/'.$file_array[$i]);$count_out = (int)file_get_contents('out/'.$file_array[$i]);$name = basename($file_array[$i], '.txt');// заносим в массив// ключи массива - кол-во переходов$array[$count_in] = '<div class="b">'.$name.' ['.$count_in.'/'.$count_out.']<a href="out.php?site=http://'.$name.'">&#187;</a></div>';}}// сортируем массивrsort($array);//выводимfor($i=0; $i<$file_count; ++$i){print $array[$i];}if (($file_count > 0) AND ($page != 0)){$prev_page = $page -1;echo'<br/><a href="'.$_SERVER['PHP_SELF'].'?page='.$prev_page.'">назад</a><br/>';}if (($file_count > 0) AND ($last_record < $file_count)){$next_page = $page + 1;echo'<br/><a href="'.$_SERVER['PHP_SELF'].'?page='.$next_page.'">далее</a><br/>';}echo'<br/>Друзей/Партнёров: '.$file_count.'<br/>';echo'<a href="../index.php">На главную</a>';}closedir($dp);include"../temp/footer.php";?>
возможности проверить работоспособность не было, поэтому проверяй сам.
в целом логика - в первом цикле заносим кол-во переходов в массив, во втором цикле в зависимости от переходов выводим.

P.S. исправил. код доваольно запутанный.

P.P.S снова исправил
Отредактировано Gemorroj (2008.11.10 16:04)
#3. DjBoBaH Off (-1)
Участник
2008.11.10 14:02
как это сложно всё гГ лан,ща пойду тестану smile
#4. DjBoBaH Off (-1)
Участник
2008.11.10 14:02
Неа,чёт не катит...
1.Счётчик $count_out не работает.
2.Не отображаются сайты,эт '.$name.' чёт не пашет.
Но сортировка работает smile
Отредактировано DjBoBaH (2008.11.10 14:02)
#5. Gemorroj Off (107)
Administrator
2008.11.10 14:02
исправил в том же посте.
#6. DjBoBaH Off (-1)
Участник
2008.11.10 15:03
Сортировка работает smile
Счётчики пашут smile
Сайты отображаются...но вместо test.ru кажет test
Попробовал изменить значение $name вот так
Код:
$name = explode('.txt',$file_array[$i]);
,но не помогло
#7. Gemorroj Off (107)
Administrator
2008.11.10 16:04
ок, исправил
#8. DjBoBaH Off (-1)
Участник
2008.11.10 17:05
Заработало...ток почему-то снова сортировка не катит
#9. Gemorroj Off (107)
Administrator
2008.11.10 18:06
перепроверь. все что я изменил это $name = basename($file_array[$i], '.txt');
#10. DjBoBaH Off (-1)
Участник
2008.11.10 18:06
Эт всё правильно,я с форума код копировал,мож просто я перепутал,что сортировка работала
Страниц: 1 2 3 Все
Главная
WEB
PunBB Mod v0.6.2
0.014 s