Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Pusta tabela
Forum PHP.pl > Forum > Przedszkole
Nimlot20
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. ?>
erix
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. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.