Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Pusta tabela
Nimlot20
post 12.03.2010, 18:18:48
Post #1





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 20.02.2010

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


Mecze sie z pewnym skryptem i nie za bardzo wiem jak moznaby sprawdzic czy dana tabela jest pusta. Chodzi mi o tabele killers w bazie xyz

  1. <?php
  2. $main_content .= '<div style="text-align: center; font-weight: bold;">Top 30 frags on ' . $config['server']['serverName'] . '</div>
  3. <table border="0" cellspacing="1" cellpadding="4" width="100%">
  4. <tr bgcolor="' . $config['site']['vdarkborder'] . '">
  5. <td class="white" style="text-align: center; font-weight: bold;">Name</td>
  6. <td class="white" style="text-align: center; font-weight: bold;">Frags</td>
  7. </tr>';
  8.  
  9. $i = 0;
  10. foreach($SQL->query('SELECT `p`.`name` AS `name`, COUNT(`p`.`name`) as `frags`
  11. FROM `killers` k
  12. LEFT JOIN `player_killers` pk ON `k`.`id` = `pk`.`kill_id`
  13. LEFT JOIN `players` p ON `pk`.`player_id` = `p`.`id`
  14. WHERE `k`.`unjustified` = 1 AND `k`.`final_hit` = 1
  15. GROUP BY `name`
  16. ORDER BY `frags` DESC, `name` ASC
  17. LIMIT 0,30;') as $player)
  18. {
  19. $i++;
  20. $main_content .= '<tr bgcolor="' . (is_int($i / 2) ? $config['site']['lightborder'] : $config['site']['darkborder']) . '">
  21. <td><a href="?subtopic=characters&name=' . urlencode($player['name']) . '">' . $player['name'] . '</a></td>
  22. <td style="text-align: center;">' . $player['frags'] . '</td>
  23. </tr>';
  24. }
  25.  
  26. $main_content .= '</table>';
  27.  
  28. $zapytanie = $SQL->query('SELECT id, xyz FROM `killers` WHERE id IS NULL;') //sprawdzanie czy tabela jest pusta
  29.  
  30. if (!mysql_num_rows($zapytanie))
  31. $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><B>Top 30 frags on ' . $config['server']['serverName'] . '</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1><TR><TD>Currently nobody has one or more frags.</TD></TR></TABLE></TD></TR></TABLE><BR>';
  32.  
  33. ?>


Ten post edytował Nimlot20 12.03.2010, 18:19:32
Go to the top of the page
+Quote Post
erix
post 12.03.2010, 18:28:02
Post #2





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




A nie prościej przed pętlą dać coś takiego?

  1. $isEmpty = true;
  2. foreach(){
  3.  
  4. # ...
  5.  
  6. $isEmpty = false;
  7. }
  8.  
  9. if($isEmpty){
  10. # pusto tu jak u kościelnego w kieszeni
  11. }


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

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

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: 18.07.2025 - 18:20