Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]While i kolorowanie tych samych wartości
Deusx
post
Post #1





Grupa: Zarejestrowani
Postów: 126
Pomógł: 2
Dołączył: 27.08.2006

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


Witam, chodzi mi tutaj o listę osób, wyciąganych pętlą po "last_online" (ostatni czas aktywności)


Pętla wyciąga każdego, gdzie last_online - 86400. Czyli aktywnych przez ostatnie 24 godziny.

Wszystko jest ok, osoby są pokazane jednak tutaj jest moje pytanie, mam np 4 osoby:


osoba IP
nick 1.1.1.1
nick1 1.1.1.2
nick2 1.1.1.3
nick4 1.1.1.1


Jak zauważamy nick i nick4 mają to samo IP. Chodzi mi o to, żeby te osoby były np pokolorowane na czerwono, czyli

if (jest to samo IP) koloruj czerwono

Czyli tak

osoba IP
nick 1.1.1.1
nick1 1.1.1.2
nick2 1.1.1.3
nick4 1.1.1.1

Tylko jak to zrobić, żeby pętla wiedziała (skrypt), że wyświetla duplikat?

Ten post edytował Deusx 28.05.2010, 21:30:56
Go to the top of the page
+Quote Post
Nh2003
post
Post #2





Grupa: Zarejestrowani
Postów: 81
Pomógł: 14
Dołączył: 3.10.2007

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


Zrob sobie tabelke tymczasowa i zapisuj do niej juz wystepujace ip, w kazdej iteracji petli sprawdzaj in_array i juz wiesz czy ip byl wyswietlony czy nie.
Go to the top of the page
+Quote Post
Deusx
post
Post #3





Grupa: Zarejestrowani
Postów: 126
Pomógł: 2
Dołączył: 27.08.2006

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


Tabelke tymczasową ? To nie SQL ? Mi chodzi o samo PHP, zrobiłem tablice, jednak nie bardzo chce to działać, zobaczcie sami:


  1. $doba = doquery("SELECT * FROM {{table}} WHERE `onlinetime` >= '". (time() - 86400) ."' ORDER BY `". $TypeSort ."` ASC;", 'users');
  2. $Count = 0;
  3. $Color = "lime";
  4. $a = 0;
  5. while ( $TheUser = mysql_fetch_array($doba) ) {
  6. if ($PrevIP != "") {
  7. for ($a = 0; $a <= 200; $a++) {
  8. if ($PrevIP[$a] == $TheUser['user_lastip']) {
  9. $Color = "red";
  10. } else {
  11. $Color = "lime";
  12. }
  13. }
  14. }
  15. $Bloc['name'] = $TheUser['username'];
  16. $Bloc['color'] = $Color;
  17. $Bloc['ip'] = $TheUser['user_lastip'];
  18. $PrevIP[$a] = $TheUser['user_lastip'];
  19. $Prevuser[$a] = $TheUser['username'];
  20. $Count++;
  21. $a++;
  22. }


Ten post edytował Deusx 28.05.2010, 22:31:17
Go to the top of the page
+Quote Post
Nh2003
post
Post #4





Grupa: Zarejestrowani
Postów: 81
Pomógł: 14
Dołączył: 3.10.2007

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


Źle się wyraziłem - oczywiście chodziło mi o zwykłą tablicę w php.

Co do kodu - ja bym zrobił tak:

  1. $aUzyteIp = array();
  2. while ( $TheUser = mysql_fetch_array($doba) ) {
  3. $Bloc['name'] = $TheUser['username'];
  4. $Bloc['color'] = $Color;
  5.  
  6. if (in_array($TheUser['user_lastip'],$aUzyteIp)) {
  7. echo 'powtarza sie';
  8. } else {
  9. $aUzyteIp[] = $TheUser['user_lastip'];
  10. }
  11. $Bloc['ip'] = $TheUser['user_lastip'];
  12. $PrevIP[$a] = $TheUser['user_lastip'];
  13. $Prevuser[$a] = $TheUser['username'];
  14. $Count++;
  15. $a++;
  16. }
Go to the top of the page
+Quote Post
Deusx
post
Post #5





Grupa: Zarejestrowani
Postów: 126
Pomógł: 2
Dołączył: 27.08.2006

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


Dzięki, teraz mam pytanie, żeby każde powtarzające IP zapisywało się do pliku, jak to zrobić?

Ten post edytował Deusx 29.05.2010, 10:12:09
Go to the top of the page
+Quote Post
jaslanin
post
Post #6





Grupa: Zarejestrowani
Postów: 511
Pomógł: 143
Dołączył: 13.03.2010
Skąd: Jasło

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


http://www.google.pl/#hl=pl&q=php+zapi...6881e05a59bd9e7

http://forum.php.pl/index.php?showtopic=88611


--------------------
Good luck and happy PHP'ing
Go to the top of the page
+Quote Post
Nh2003
post
Post #7





Grupa: Zarejestrowani
Postów: 81
Pomógł: 14
Dołączył: 3.10.2007

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


  1. $aUzyteIp = array();
  2. $aDuble = array();
  3. while ( $TheUser = mysql_fetch_array($doba) ) {
  4. $Bloc['name'] = $TheUser['username'];
  5. $Bloc['color'] = $Color;
  6.  
  7. if (in_array($TheUser['user_lastip'],$aUzyteIp)) {
  8. echo 'powtarza sie';
  9. $aDuble[] = $TheUser['user_lastip'];
  10. } else {
  11. $aUzyteIp[] = $TheUser['user_lastip'];
  12. }
  13. $Bloc['ip'] = $TheUser['user_lastip'];
  14. $PrevIP[$a] = $TheUser['user_lastip'];
  15. $Prevuser[$a] = $TheUser['username'];
  16. $Count++;
  17. $a++;
  18. }
  19. if (!empty($aDuble)) {
  20. file_put_contents('zdublowaneip.txt',serialize($aDuble));
  21. }


Oczywiscie format zapisu musisz dostosowac do swoich potrzeb.
Go to the top of the page
+Quote Post
Deusx
post
Post #8





Grupa: Zarejestrowani
Postów: 126
Pomógł: 2
Dołączył: 27.08.2006

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


Żeby nie kombinować, dałem tutaj łatwiejsze znaki z skróciłem kod, jednak nadal mi to nie wchodzi.

Dokładniej chodzi mi o zapis do bazy (myślałem, że na podstawie jakiegoś przykładu mi się uda.

Mam cały plik:

  1. <?php
  2.  
  3. if($user['access'] == "0") {
  4. message("Przepraszamy ale nie masz dostępu do tej części Panelu Administracyjnego!","Informacja");
  5. }
  6. includeLang('admin');
  7.  
  8. if ($_GET['cmd'] == 'sort') {
  9. $TypeSort = $_GET['type'];
  10. } else {
  11. $TypeSort = "id";
  12. }
  13.  
  14. $PageTPL = gettemplate('admin/overview_body1');
  15. $RowsTPL = gettemplate('admin/overview_rows1');
  16.  
  17. $parse = $lang;
  18. $parse['dpath'] = $dpath;
  19. $parse['mf'] = $mf;
  20. $parse['adm_ov_data_yourv'] = colorRed(VERSION);
  21.  
  22. $Last15Mins = doquery("SELECT * FROM {{table}} WHERE `onlinetime` >= '". (time() - 120) ."' ORDER BY `". $TypeSort ."` ASC;", 'users');
  23. $Count = 0;
  24. $Color = "lime";
  25. $a = 1;
  26. $aUzyteIp = array();
  27. while ( $TheUser = mysql_fetch_array($Last15Mins) ) {
  28.  
  29. $a = $a + 1;
  30. if (in_array($TheUser['user_lastip'],$aUzyteIp)) {
  31. echo 'powtarza sie ', $TheUser['user_lastip'] ;
  32. //Jak powinno wyglądac zapytanie, ktore doda IP i username powtarzających się IP
  33. } else {
  34. $aUzyteIp[] = $TheUser['user_lastip'];
  35. }
  36.  
  37.  
  38. $UserPoints = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '" . $TheUser['id'] . "';", 'statpoints', true);
  39. $Bloc['dpath'] = $dpath;
  40. $Bloc['adm_ov_altpm'] = $lang['adm_ov_altpm'];
  41. $Bloc['adm_ov_wrtpm'] = $lang['adm_ov_wrtpm'];
  42. $Bloc['adm_ov_data_id'] = $TheUser['id'];
  43. $Bloc['adm_ov_data_name'] = $TheUser['username'];
  44. $Bloc['adm_ov_data_agen'] = $TheUser['user_agent'];
  45. $Bloc['adm_ov_data_clip'] = $Color;
  46. $Bloc['adm_ov_data_adip'] = $TheUser['user_lastip'];
  47. $Bloc['adm_ov_data_ally'] = $TheUser['ally_name'];
  48. $Bloc['adm_ov_data_point'] = pretty_number ( $UserPoints['total_points'] );
  49. $Bloc['adm_ov_data_activ'] = pretty_time ( time() - $TheUser['onlinetime'] );
  50. $Bloc['adm_ov_data_pict'] = "m.gif";
  51. $PrevIP[$a] = $TheUser['user_lastip'];
  52. $PrevIP1[$a] = $TheUser['username'];
  53. $parse['adm_ov_data_table'] .= parsetemplate( $RowsTPL, $Bloc );
  54. $Count++;
  55. }
  56.  
  57. $parse['adm_ov_data_count'] = $Count;
  58.  
  59. ?>


i Mamy baze:
zgloszoneIP
id nicki IP

czyli powinno być np. tak:

1 test,test2 1.1.1.1


Bardzo proszę o pomoc
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 07:47