Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Sprawdz czy istnieje wpis w bazie
atyll
post
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 21.07.2007

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


Witam

Napisałem kod, który sprawdza czy w tabeli player_storage, istnieje wpis key = 100 dla ID gracza(player_id)
Pokazuje poprawnie gdy wpis istnieje, lecz nie wyświetla się nic, gdy wpis nie istnieje.

Mój kod:
  1. <?php
  2. $GetPlayerID = $player->attrs['id']; // zaladuj ID gracza
  3.  
  4. $result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =$GetPlayerID AND `key` =100");
  5.  
  6. while($info = mysql_fetch_array($result))
  7. {
  8. if($info['key'] == 100 && $info['player_id'] == $GetPlayerID)
  9. {
  10. // If player completed the quest, display result
  11. echo 'This player completed annihilator.';
  12. }
  13. else
  14. {
  15. die("QUEST NOT COMPLETED!");
  16. }
  17. }
  18.  
  19. ?>


Moja baza wygląda tak:
(IMG:http://oi49.tinypic.com/2i0aofp.jpg)

Mógłby mi ktoś pomóc?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Szymciosek
post
Post #2





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

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


Hmm ja bym kombinował coś na wzór

  1. if (!empty($result)
  2. {
  3. //jesli nie jest pust
  4. while...
  5. }
  6. else
  7. {
  8. //error o nieistniejącym wpisie
  9. }
Go to the top of the page
+Quote Post
atyll
post
Post #3





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 21.07.2007

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


Zrobiłem tak i działa elegancko (IMG:style_emoticons/default/smile.gif)

  1. <?php
  2. $result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` = '".$GetPlayerID."' AND `key` = '100'");
  3. $info = mysql_fetch_array($result);
  4.  
  5. if($info['key'] == 100 && $info['player_id'] == $GetPlayerID)
  6. {
  7. echo '<img src="images/complete.png"/>';
  8. }
  9. else
  10. {
  11. echo '<img src="images/incomplete.png"/>';
  12. }
  13. ?>
Go to the top of the page
+Quote Post
mmmmmmm
post
Post #4





Grupa: Zarejestrowani
Postów: 1 421
Pomógł: 310
Dołączył: 18.04.2012

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


Bez sensu. Skoro dajesz w warunkach :
  1. `player_id` = '".$GetPlayerID."' AND `key` = '100'

to co by miało się znajdować w :
  1. if($info['key'] == 100 && $info['player_id'] == $GetPlayerID)

(IMG:style_emoticons/default/questionmark.gif)
Coś innego?
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: 22.08.2025 - 19:12