Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]while
mit2
post
Post #1





Grupa: Zarejestrowani
Postów: 160
Pomógł: 5
Dołączył: 4.08.2010

Ostrzeżenie: (40%)
XX---


witam mam problem z while mam taki kod
  1. $has = "SELECT * FROM has";
  2. $has = mysql_query("$has");
  3. while($haslo = mysql_fetch_array($has))
  4. {
  5. if($ser['id'] == $haslo['idser'])
  6. {
  7. $is = "UPDATE has SET haslo='$_POST[haslo]' WHERE idser='$ser[id]'";
  8. $is = mysql_query("$is");
  9. echo'update';
  10. }
  11. else
  12. {
  13. $in = "INSERT INTO has VALUES ('$ser[id]', '$_POST[haslo]')";
  14. $in = mysql_query($in);
  15. echo'zrobione';
  16. }
  17. }

i chce w nim aby gdy w $haslo[idser] jest id serwera to robi update a jeżeli go nie ma to robi insert. i jeżeli mam wogule coś w tabeli to robi insert gdy jest juz w tabeli to robi insert i update jednoczesnie
Go to the top of the page
+Quote Post
Hpsi
post
Post #2





Grupa: Zarejestrowani
Postów: 483
Pomógł: 50
Dołączył: 15.03.2005
Skąd: Poznań

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


nie do końca rozumiem twój tok rozumowania i to co chcesz zrobić, ale jeśli dobrze zrozumiałem zainteresuj się komenda REPLACE w mysqlu
Go to the top of the page
+Quote Post
sadistic_son
post
Post #3





Grupa: Zarejestrowani
Postów: 1 495
Pomógł: 245
Dołączył: 1.07.2009
Skąd: Bydgoszcz

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


Pokaż gdzie tworzysz $ser['id']. Ten fragment kodu jest cały w innej pętli?
Go to the top of the page
+Quote Post
mit2
post
Post #4





Grupa: Zarejestrowani
Postów: 160
Pomógł: 5
Dołączył: 4.08.2010

Ostrzeżenie: (40%)
XX---


problem rozwiązany sam zrobiłem
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: 23.08.2025 - 07:10