Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [PHP]Zapytanie IF
kurczak610
post
Post #1





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Witam ponownie tongue.gif exclamation.gif
Mam takie zapytanie IF:
  1. <?php
  2. if($rangamin == $rangamax OR $rangamin => $rangamax) {
  3. mysql_query("UPDATE users1 SET ranga=ranga+1 WHERE id=$_SESSION[userid]") or die(mysql_error());
  4. }
  5. ?>


I wywala bład:
Parse error: syntax error, unexpected T_DOUBLE_ARROW

Ale jak wywale z kodu:
  1. <?php
  2. OR $rangamin => $rangamax
  3. ?>
Jest ok

Dlaczego?
Go to the top of the page
+Quote Post
bliitz
post
Post #2





Grupa: Zarejestrowani
Postów: 155
Pomógł: 12
Dołączył: 5.04.2008

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


zamiast OR spróbuj ||


--------------------
Go to the top of the page
+Quote Post
kurczak610
post
Post #3





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


To samo ;/
Go to the top of the page
+Quote Post
mike
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Podstawy podstaw. Operatory porównań

Następnym razem pisz na Przedszkolu.
Go to the top of the page
+Quote Post
kurczak610
post
Post #5





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


A dlaczego jak dodam do tego:
  1. <?php
  2. mysql_query("UPDATE users1 SET rangamin=rangamin-$rangamin WHERE id=$_SESSION[userid]") or die(mysql_error());
  3. ?>

To mam bład:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=1' at line 1
Go to the top of the page
+Quote Post
destroyerr
post
Post #6





Grupa: Zarejestrowani
Postów: 879
Pomógł: 189
Dołączył: 14.06.2006
Skąd: Bytom

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


Zastanów się nad sensownością Twojego warunku. Najpierw sprawdzasz czy jest równe, a potem chcesz sprawdzać czy jest równe lub większe. Wystarczy tylko jeden warunek.
Twój zapis drugiego warunku powinien wyglądać tak:
  1. <?php
  2. $rangamin >= $rangamax
  3. ?>
Go to the top of the page
+Quote Post
kurczak610
post
Post #7





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


No bo mi chodzi o system rang.
Mam 3 pola w tabeli:
ranga - id rangi
rangamin - gdy bedzie rowne rangamax wtedy do rangi dodaje 1 i od tego odejmuje tyle ile jest w rangamax
rangamax

Chyba ze macie jakis inny system rang tongue.gifP
Go to the top of the page
+Quote Post
maly_swd
post
Post #8





Grupa: Zarejestrowani
Postów: 744
Pomógł: 118
Dołączył: 14.02.2009
Skąd: poziome

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


  1. <?php
  2. mysql_query("UPDATE users1 SET rangamin=rangamin-{$rangamin} WHERE id={$_SESSION[userid]}") or die(mysql_error());
  3. ?>


--------------------
śmieszne obrazki
Kryzys: Ser jem spleśniały, wino piję stare i samochód mam bez dachu..
Go to the top of the page
+Quote Post
gcdreak
post
Post #9





Grupa: Zarejestrowani
Postów: 365
Pomógł: 8
Dołączył: 16.12.2008

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


Używaj mysqli!
Go to the top of the page
+Quote Post
kurczak610
post
Post #10





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Mam coś takiego:
  1. <?php
  2. if($pokazranga['rangamin'] >= $pokazranga['rangamax']) {
  3. mysql_query("UPDATE users1 SET ranga=ranga+1 WHERE id=$_SESSION[userid]") or die(mysql_error());
  4.                              
  5.  
  6.               if($pokazranga['ranga'] == 1)
  7.               mysql_query("UPDATE users1 SET rangamax=40 WHERE id=$_SESSION[userid]") or die(mysql_error());
  8.               mysql_query("UPDATE users1 SET rangamin=rangamin-40 WHERE id=$_SESSION[userid]") or die(mysql_error());
  9.              
  10.               if($pokazranga['ranga'] == 2)
  11.               mysql_query("UPDATE users1 SET rangamax=100 WHERE id=$_SESSION[userid]") or die(mysql_error());
  12.               mysql_query("UPDATE users1 SET rangamin=rangamin-100 WHERE id=$_SESSION[userid]") or die(mysql_error());
  13.  
  14.               if($pokazranga['ranga'] == 3)
  15.               mysql_query("UPDATE users1 SET rangamax=250 WHERE id=$_SESSION[userid]") or die(mysql_error());
  16.               mysql_query("UPDATE users1 SET rangamin=rangamin-250 WHERE id=$_SESSION[userid]") or die(mysql_error());
  17.              
  18.               if($pokazranga['ranga'] == 4)
  19.               mysql_query("UPDATE users1 SET rangamax=550 WHERE id=$_SESSION[userid]") or die(mysql_error());
  20.               mysql_query("UPDATE users1 SET rangamin=rangamin-550 WHERE id=$_SESSION[userid]") or die(mysql_error());
  21.  
  22.               if($pokazranga['ranga'] == 5)
  23.               mysql_query("UPDATE users1 SET rangamax=1300 WHERE id=$_SESSION[userid]") or die(mysql_error());
  24.               mysql_query("UPDATE users1 SET rangamin=rangamin-1300 WHERE id=$_SESSION[userid]") or die(mysql_error());
  25.              
  26.               if($pokazranga['ranga'] == 6)
  27.               mysql_query("UPDATE users1 SET rangamax=3000 WHERE id=$_SESSION[userid]") or die(mysql_error());
  28.               mysql_query("UPDATE users1 SET rangamin=rangamin-3000 WHERE id=$_SESSION[userid]") or die(mysql_error());
  29.  
  30.               if($pokazranga['ranga'] == 7)
  31.               mysql_query("UPDATE users1 SET rangamax=7500 WHERE id=$_SESSION[userid]") or die(mysql_error());
  32.               mysql_query("UPDATE users1 SET rangamin=rangamin-7500 WHERE id=$_SESSION[userid]") or die(mysql_error());              
  33.  
  34.               if($pokazranga['ranga'] == 8)
  35.               mysql_query("UPDATE users1 SET rangamax=18000 WHERE id=$_SESSION[userid]") or die(mysql_error());
  36.  
  37. }
  38. ?>


Ale odejmuje mi za duzo w rangamin, co to zrobić? tongue.gifP
Go to the top of the page
+Quote Post
gcdreak
post
Post #11





Grupa: Zarejestrowani
Postów: 365
Pomógł: 8
Dołączył: 16.12.2008

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


Cytat(kurczak610 @ 16.06.2009, 17:29:04 ) *
Ale odejmuje mi za duzo w rangamin, co to zrobić? tongue.gif P


Co to znaczy 'za dużo'? O ile za dużo?
Go to the top of the page
+Quote Post
kurczak610
post
Post #12





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Mam np. 1 range:
  1. <?php
  2. if($pokazranga['ranga'] == 1)
  3.               mysql_query("UPDATE users1 SET rangamax=40 WHERE id=$_SESSION[userid]") or die(mysql_error());
  4.               mysql_query("UPDATE users1 SET rangamin=rangamin-40 WHERE id=$_SESSION[userid]") or die(mysql_error());
  5. ?>


Zamiast odejmować mi 40 odejmuje wszystko ze skryptu tongue.gif
Go to the top of the page
+Quote Post
erix
post
Post #13





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




http://forum.php.pl/index.php?s=&showt...st&p=620493


--------------------

ZCE :: Pisząc PW załączaj LINK DO TEMATU i TYLKO w sprawach moderacji :: jakiś błąd - a TREŚĆ BŁĘDU? :: nie ponaglaj z odpowiedzią via PW!
Go to the top of the page
+Quote Post
kurczak610
post
Post #14





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Daj jakis przykład mysqli bo nigdy ich nie uzywałem tongue.gifP
Go to the top of the page
+Quote Post
erix
post
Post #15





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




Porównaj sobie zapis tego zapytania z Twoim...


--------------------

ZCE :: Pisząc PW załączaj LINK DO TEMATU i TYLKO w sprawach moderacji :: jakiś błąd - a TREŚĆ BŁĘDU? :: nie ponaglaj z odpowiedzią via PW!
Go to the top of the page
+Quote Post
kurczak610
post
Post #16





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Mam dawać np. gdy odejmuje, zmienna $rangamax w {}questionmark.gif
Go to the top of the page
+Quote Post
hostingekspert
post
Post #17





Grupa: Zarejestrowani
Postów: 51
Pomógł: 5
Dołączył: 12.04.2007
Skąd: 1=1

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


tak,

popraw również wszędzie

  1. <?php
  2. $_SESSION[userid]
  3. ?>


na

  1. <?php
  2. {$_SESSION['userid']}
  3. ?>


a zamiast używać 8krotnie instrukcji warunkowej if, użyj switch

Ten post edytował hostingekspert 17.06.2009, 17:43:43
Go to the top of the page
+Quote Post
Ociu
post
Post #18





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Tymczasem ja przeniosę do przedszkola.
Go to the top of the page
+Quote Post
kurczak610
post
Post #19





Grupa: Zarejestrowani
Postów: 87
Pomógł: 2
Dołączył: 3.05.2009

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


Więc mam coś takiego:
  1. <?php
  2. if($pokazranga['ranga'] == 1)
  3.               mysql_query("UPDATE users1 SET rangamax=40 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  4.               mysql_query("UPDATE users1 SET rangamin=rangamin-40 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  5.              
  6.               if($pokazranga['ranga'] == 2)
  7.               mysql_query("UPDATE users1 SET rangamax=100 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  8.               mysql_query("UPDATE users1 SET rangamin=rangamin-100 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  9.  
  10.               if($pokazranga['ranga'] == 3)
  11.               mysql_query("UPDATE users1 SET rangamax=250 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  12.               mysql_query("UPDATE users1 SET rangamin=rangamin-250 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  13.              
  14.               if($pokazranga['ranga'] == 4)
  15.               mysql_query("UPDATE users1 SET rangamax=550 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  16.               mysql_query("UPDATE users1 SET rangamin=rangamin-550 WHERE id=$_SESSION[userid]") or die(mysql_error());
  17.  
  18.               if($pokazranga['ranga'] == 5)
  19.               mysql_query("UPDATE users1 SET rangamax=1300 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  20.               mysql_query("UPDATE users1 SET rangamin=rangamin-1300 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  21.              
  22.               if($pokazranga['ranga'] == 6)
  23.               mysql_query("UPDATE users1 SET rangamax=3000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  24.               mysql_query("UPDATE users1 SET rangamin=rangamin-3000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  25.  
  26.               if($pokazranga['ranga'] == 7)
  27.               mysql_query("UPDATE users1 SET rangamax=7500 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  28.               mysql_query("UPDATE users1 SET rangamin=rangamin-7500 WHERE id={$_SESSION['userid']}") or die(mysql_error());              
  29.  
  30.               if($pokazranga['ranga']== 8)
  31.               mysql_query("UPDATE users1 SET rangamax=18000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  32. ?>



Ale jest to samo. A nie wiem jak zrobić na swith bo ja to uzywam tylko do podstron tongue.gif
Go to the top of the page
+Quote Post
Wicepsik
post
Post #20





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

Ostrzeżenie: (20%)
X----


  1. <?php
  2. if($pokazranga['ranga'] == 1){
  3.              mysql_query("UPDATE users1 SET rangamax=40 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  4.              mysql_query("UPDATE users1 SET rangamin=rangamin-40 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  5.                 }
  6.              if($pokazranga['ranga'] == 2){
  7.              mysql_query("UPDATE users1 SET rangamax=100 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  8.              mysql_query("UPDATE users1 SET rangamin=rangamin-100 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  9.                    }
  10.              if($pokazranga['ranga'] == 3){
  11.              mysql_query("UPDATE users1 SET rangamax=250 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  12.              mysql_query("UPDATE users1 SET rangamin=rangamin-250 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  13.                  }    
  14.            
  15.              if($pokazranga['ranga'] == 4){
  16.              mysql_query("UPDATE users1 SET rangamax=550 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  17.              mysql_query("UPDATE users1 SET rangamin=rangamin-550 WHERE id=$_SESSION[userid]") or die(mysql_error());
  18.                  }    
  19.  
  20.              if($pokazranga['ranga'] == 5){
  21.              mysql_query("UPDATE users1 SET rangamax=1300 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  22.              mysql_query("UPDATE users1 SET rangamin=rangamin-1300 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  23.                  }    
  24.            
  25.              if($pokazranga['ranga'] == 6){
  26.              mysql_query("UPDATE users1 SET rangamax=3000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  27.              mysql_query("UPDATE users1 SET rangamin=rangamin-3000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  28.                  }    
  29.  
  30.              if($pokazranga['ranga'] == 7){
  31.              mysql_query("UPDATE users1 SET rangamax=7500 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  32.              mysql_query("UPDATE users1 SET rangamin=rangamin-7500 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  33.                  }                
  34.  
  35.              if($pokazranga['ranga']== 8){
  36.              mysql_query("UPDATE users1 SET rangamax=18000 WHERE id={$_SESSION['userid']}") or die(mysql_error());
  37.                  }
  38. ?>



http://php.net/manual/en/control-structures.if.php
Przykład drugi.

Ten post edytował Wicepsik 17.06.2009, 19:47:10


--------------------
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 22.08.2025 - 01:11