Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql] Wyszukanie brakujących liczb z pewnego zakresu
novaczek
post 6.07.2006, 07:29:31
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


sytuacja wyglada nastepujaco
w tabeli 'osoby' jest pole 'nr_lic'
obecnie 'nr_lic' ma wartości od 1001 do 1900 (wartosci beda rosly) ale niestety w tym przedziale brakuje kilkunastu liczb
Szukam sposobu na wyswietlenie właśnie tych brakujących liczb
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 13)
Cysiaczek
post 6.07.2006, 07:37:20
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Chodzi Ci o wyswietlenie TYLKO tych brakujacych liczb, czy po prostu wszystkiuch liczb. Podaj kontkekst, bo mam jeszcze jedną interpretację w zanadrzu.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 6.07.2006, 07:40:28
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


Chodzi tylko o brakujące liczby
Go to the top of the page
+Quote Post
Cysiaczek
post 6.07.2006, 08:00:40
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Dobra. spróbujemy w ten deseń:

Zakładam, że dobrze zrozumiałem, że masz te liczby w osobnych rekordach.

To tylko fragment algorytmu - coś spaprałem i musze przemyślec ...
  1. <?php
  2.  
  3. $i=1001; //na chama dajemy integer
  4.  
  5. $start=$i+1; //dla pierwszego przebiegu petli
  6. $stan=0;
  7.  
  8. while ($result=mysql_fetch_array($query)){
  9.  
  10. if ($stan==0){
  11. $stan=1;
  12. $i=$start;
  13. }
  14.  
  15. // $result[0] to twoja liczba ok?
  16. if ($result[0] - 1 == $i){//nic nie rób}
  17. else {
  18. print $result[0];
  19. }
  20.  
  21. $i=$result[0];
  22.  
  23. }
  24. ?>


Wogóle to zamotałem ...

Ten post edytował Cysiaczek 6.07.2006, 08:15:24


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 6.07.2006, 08:05:56
Post #5





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


smile.gif
oczywiscie te liczby sa w odzielnych rekordach
Go to the top of the page
+Quote Post
Cysiaczek
post 6.07.2006, 08:07:56
Post #6





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Powyższe powinno działac - ewentualnie troszkę przeróbek sobie dokonasz smile.gif

Znalazłem BUGA - dla pierwszego rekordu nie zadziała :|

Ten post edytował Cysiaczek 6.07.2006, 08:09:33


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 6.07.2006, 08:14:09
Post #7





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


no wlasnie apropo przerobek.... ja powinienem byc chyba w zlobku:)
jak podpiac skrypt do mojej tabeli?? (tam sa tez inne kolumny oczywiscvie)
Go to the top of the page
+Quote Post
Cysiaczek
post 6.07.2006, 08:16:44
Post #8





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




teraz powinno działac - nie jest to oczywiście piekny kod, ale ujdzie w tłoku.

Nie musisz podinać do tabeli. Chyba masz jakiś kod, który przetwarza dane prawda?

Ten post edytował Cysiaczek 6.07.2006, 08:17:53


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 6.07.2006, 08:21:30
Post #9





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


no wlasnie to mialby byc oddzielny, niezalezny skrypt informacyjny tylko dla mnie, nie wpiety nigdzie (oczywiscie z conectem do bazy)... ale z selectem nie bedzie problemu (chyba)

wyskakuje jakis blad w lini z else

czy takie zapytanie jest OK?
  1. $query = mysql_query("SELECT os_lic FROM `wnba_osoby` ");


Ten post edytował novaczek 6.07.2006, 08:47:34
Go to the top of the page
+Quote Post
Cysiaczek
post 6.07.2006, 09:04:43
Post #10





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Raczej tak.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 6.07.2006, 09:06:27
Post #11





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


to jesli tak to wyskakuje blad parsera dla lini 17 w Twoim skrypcie... u mnie 21 bo jeszcze dodany conect

http://www.wnba.pl/baza/info_brakujace_lic.php

a kod wyglada tak:
  1. <? include ('connect.php');
  2.  
  3. ?>
  4. <?php
  5. $query = mysql_query("SELECT MAX(os_lic) FROM `wnba_osoby` ");
  6.  
  7. $i=1001; //na chama dajemy integer
  8.  
  9. $start=$i+1; //dla pierwszego przebiegu petli
  10. $stan=0;
  11.  
  12. while ($result=mysql_fetch_array($query)){
  13.  
  14. if ($stan==0){
  15. $stan=1;
  16. $i=$start;
  17. }
  18.  
  19. // $result[0] to twoja liczba ok?
  20. if ($result[0] - 1 == $i){//nic nie rób}
  21. else {
  22. print $result[0];
  23. }
  24.  
  25. $i=$result[0];
  26.  
  27. }
  28. ?>


Ten post edytował novaczek 6.07.2006, 09:09:59
Go to the top of the page
+Quote Post
Cysiaczek
post 6.07.2006, 09:27:01
Post #12





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




linia No 20 przenies '}' do nastepnej linii - ja podaję rozwiązanie - jak pojawią się będy parsera, to chyba umiesz sobie poradzić?


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
novaczek
post 7.07.2006, 07:24:16
Post #13





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 20.03.2006
Skąd: Piastów

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


OK... Pięknie działa tylko trzeba wprowadzić małą poprawkę



bo inaczej wyswietla wartosci ktore sa tuz po "pustej" wartosci czyli np. 1219 zamiast 1218
Jeszcze jedno. Tabela musi być posortowana rosnąco wg pola w którym szukamy "dziur"

I mały problem. Wyświetla się tez wartość startowa czyli 1000 - jak się jej pozbyc

Po kilku testach okazało się że skrypt działa poprawnie w tej postaci

  1. <?php
  2. $query = mysql_query("SELECT os_lic FROM `wnba_osoby` WHERE `os_lic` >= 200 ORDER BY `os_lic` ASC");
  3.  
  4. while ($result=mysql_fetch_array($query))
  5. {
  6.  
  7.  
  8. if ($result[0] - 1 == $i){
  9. }//nic nie rób
  10. else {
  11.  
  12. echo (($result[0] - 1).' ');
  13. }
  14.  
  15. $i=$result[0];
  16.  
  17. };
  18.  
  19. ?>


Ten post edytował novaczek 7.07.2006, 07:27:00
Go to the top of the page
+Quote Post
Cysiaczek
post 7.07.2006, 07:32:43
Post #14





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




No to ustaw ta wartość tak jak podałem - algorytm działał na pewno. Teraz widzę, że nieco zmieniłeś. Jak zaczynasz od liczby 1000, to musisz ustawić starter na 1001 (był ustawiony).


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 11:22