Advertisement
Guest User

PHP kód 2

a guest
Apr 27th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2.     $db_connect = mysqli_connect('localhost', 'katalog', 'KatalogJanda123', 'produkty', 3306);
  3.    
  4.     function nazev() {
  5.         $db_connect = mysqli_connect('localhost', 'katalog', 'KatalogJanda123', 'produkty', 3306);
  6.         $db_data = mysqli_query($db_connect, 'SELECT * FROM siesta ORDER BY id');
  7.         $id = mysqli_num_rows($db_data);
  8.        
  9.         echo '<tr>';
  10.         while ($radek = mysqli_fetch_array($db_data))
  11.         {
  12.             $i = 0;
  13.             $nazev = $radek['nazev'];
  14.             echo "<th>$nazev</th>";
  15.             $i++;
  16.            
  17.             if (!($i %2))
  18.             {
  19.                 echo '</tr>';
  20.             }
  21.             if ($id > 2 and !($i %2) and $i > 2)
  22.             {
  23.                 echo '<tr>';
  24.             }
  25.             if ($i == $id)
  26.             {
  27.                 echo '</tr>';
  28.             }
  29.         }
  30.     }
  31.    
  32.     function popis() {
  33.         $db_connect = mysqli_connect('localhost', 'katalog', 'KatalogJanda123', 'produkty', 3306);
  34.         $db_data = mysqli_query($db_connect, 'SELECT * FROM siesta ORDER BY id');
  35.         $id = mysqli_num_rows($db_data);
  36.        
  37.         echo '<tr>';
  38.         while ($radek = mysqli_fetch_array($db_data))
  39.         {
  40.             $i = 0;
  41.             $popis = $radek['popis'];
  42.             echo "<td>$popis</td>";
  43.             $i++;
  44.            
  45.             if (!($i %2))
  46.             {
  47.                 echo '</tr>';
  48.             }
  49.             if ($id>2 and !($i %2) and $i > 2)
  50.             {
  51.                 echo '<tr>';
  52.             }
  53.             if ($i == $id)
  54.             {
  55.                 echo '</tr>';
  56.             }
  57.         }
  58.     }
  59.    
  60.     function tabulka() {
  61.         echo '<table>';
  62.         nazev();
  63.         popis();
  64.         echo '</table>';
  65.     }
  66.    
  67.     if($db_connect)
  68.     {
  69.         tabulka();
  70.     }
  71.     else
  72.     {
  73.         echo 'Spojení s databází nebylo navázáno!';
  74.         echo '<br />';
  75.         echo 'Kontaktuje prosím administrátora na e-mail <a href="mailto:[email protected]">[email protected]</a> s chybovým hlášením.';
  76.         echo 'Popis chyby: ', mysqli_connect_error();
  77.         exit();
  78.     }
  79.        
  80.     if ($db_connect)
  81.         mysqli_close($db_connect);
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement