SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     require __DIR__ . '/vendor/autoload.php';
  3.  
  4.     $filterQuery = 'SELECT * FROM Kategorien';
  5.  
  6.     $produkteQuery = 'SELECT m.ID AS MahlzeitID, m.`Name`, m.Vorrat, m.Verfügbar, b.Titel, b.`Alt-Text`, b.`Binärdaten`, k.ID, z.ID, z.`Name` AS Zutatenname, IF(COUNT(m.ID)=SUM(z.Vegetarisch),1,0) AS IstVegetarisch, IF(COUNT(m.ID)=SUM(z.Vegan),1,0) AS IstVegan FROM Mahlzeiten m
  7.    LEFT JOIN MhatB mhb ON m.ID = mhb.MahlzeitID
  8.    LEFT JOIN Bilder b ON m.ID = b.ID
  9.    LEFT JOIN Kategorien k ON k.ID = m.KategorienID
  10.    LEFT JOIN MenthältZ mhz ON m.ID = mhz.MahlzeitID
  11.    LEFT JOIN Zutaten z ON z.ID = mhz.ZutatenID'; // Ihre SQL Query aus HeidiSQL
  12.  
  13.     $dotenv = Dotenv\Dotenv::create(__DIR__,'db_daten.env');
  14.     $dotenv->load();
  15.     $dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS','DB_PORT']);
  16.     $remoteConnection = mysqli_connect( getenv('DB_HOST'), getenv('DB_USER'), getenv('DB_PASS'), getenv('DB_NAME'), (int) getenv('DB_PORT'));
  17.  
  18.     if (mysqli_connect_errno()) {
  19.         printf("Konnte nicht zur entfernten Datenbank verbinden: %s\n", mysqli_connect_error());
  20.         exit();
  21.     }
  22.  
  23.     if(isset($_GET['category']) && $_GET['category'] != 11) {
  24.         $produkteQuery = $produkteQuery . " WHERE k.ID = " . '"' . $_GET['category'] . '"';
  25.  
  26.         if(isset($_GET['avail']) && $_GET['avail'] == 1)
  27.             $produkteQuery = $produkteQuery . " AND m.Verfügbar = " . $_GET['avail'];
  28.     } else {
  29.         if(isset($_GET['avail'])  && $_GET['avail'] == 1)
  30.             $produkteQuery = $produkteQuery . " WHERE m.Verfügbar = " . $_GET['avail'];
  31.     }
  32.  
  33.     $produkteQuery= $produkteQuery . " GROUP BY m.ID";
  34.    
  35.     if(isset($_GET['vegetarisch']) && $_GET['vegetarisch'] == 1) {
  36.         $produkteQuery = $produkteQuery . " HAVING IstVegetarisch = " . $_GET['vegetarisch'];
  37.        
  38.         if(isset($_GET['vegan']) && $_GET['vegan'] == 1) {
  39.             $produkteQuery = $produkteQuery . " AND IstVegan = " . $_GET['vegan'];
  40.         }
  41.     } else {
  42.         if(isset($_GET['vegan']) && $_GET['vegan'] == 1) {
  43.             $produkteQuery = $produkteQuery . " HAVING IstVegan = " . $_GET['vegan'];
  44.         }
  45.     }
  46.  
  47.     if(isset($_GET['limit']))
  48.         $produkteQuery = $produkteQuery . " LIMIT " . $_GET['limit'];
  49.  
  50.     $filterResult = mysqli_query($remoteConnection, $filterQuery);
  51.     $filterResult2 = mysqli_query($remoteConnection, $filterQuery);
  52.     $produkteResult = mysqli_query($remoteConnection, $produkteQuery);
  53.  
  54.     mysqli_close($remoteConnection); // daran denken, die Verbindung wieder zu schließen wenn sie nicht mehr benötigt ist.
  55. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top