2016-10-17 8 views
1

Ich versuche, eine Website zu machen, dass, wenn Sie auf die Anwendung klicken, öffnet es und es funktioniert im Moment, aber öffnet jede einzelne Anwendung, die offensichtlich will ich nicht.PHP - While Loop Query

Ich glaube, ich muss eine foreach loop so for every application it puts a different $ appLocation `in?

Dies ist nur ein erstes Projekt für mich, also vielleicht, wenn mir jemand in die richtige Richtung zeigen kann.

<?php 

    $appQuery = "SELECT app_name, app_location, app_status, app_image FROM applications"; 
    $select_posts = mysqli_query($conn, $appQuery); 

    if ($result = mysqli_query($conn, $appQuery)) { 

     /* fetch associative array */ 
     while ($row = mysqli_fetch_assoc($result)) { 

      $appName = $row['app_name']; // List Application Name 
      $appLocation = $row['app_location']; // List Application Location 
      $appStatus = $row['app_status']; // List Application Status - 1 = Enabled/0 = Disabled 
      $appImage = $row['app_image']; // List Application Image Locations 
?> 


      <!-- Tile with image container --> 
      <div class="tile"> 
       <div class="tile-content"> 
        <div class="image-container"> 
         <form method="post"> 
          <div class="frame"> 
           <button name="appButton"><img src="<?php echo $appImage ?>"></button> 
          </div> 
         </form> 
         <?php 
          if (isset($_POST['appButton'])) { 
           exec("start $appLocation"); 
          } 
         ?> 
        </div> 
       </div> 
      </div> 
<?php 
     } 
?> 
+0

zunächst eingedenk - laufen nicht die Abfrage zweimal, entfernen Sie '$ select_posts = mysqli_query ($ conn, $ appQuery);' Und da die Buttons alle gleich benannt sind, wird das Klicken auf eines von ihnen ALLE Apps veranlassen, – RamRaider

Antwort

1

Sie könnten in dieser Richtung versuchen, meine vorherigen Kommentare

<?php 

    $appQuery = "SELECT app_name, app_location, app_status, app_image FROM applications"; 
    if ($result = mysqli_query($conn, $appQuery)) { 

     /* fetch associative array */ 
     while ($row = mysqli_fetch_assoc($result)) { 
      $appName = $row['app_name']; // List Application Name 
      $appLocation = $row['app_location']; // List Application Location 
      $appStatus = $row['app_status']; // List Application Status - 1 = Enabled/0 = Disabled 
      $appImage = $row['app_image']; // List Application Image Locations 


?> 

     <!-- Tile with image container --> 
     <div class="tile"> 
      <div class="tile-content"> 
       <form method="post"> 
        <div class="image-container"> 
        <?php 
         $bttn = 'appButton_'.$appName; 
         echo " 
          <div class='frame'> 
           <button name='{$bttn}'><img src='{$appImage}' /></button> 
          </div>"; 
        ?> 



       </form> 
         <?php 
          if (isset($_POST[ $bttn ])) { 
           exec("start $appLocation"); 
          } 
         ?> 
       </div> 
      </div> 
     </div> 
+0

zu starten, aber es reagiert nicht, wenn ich auf meine Anwendungen klicke, jetzt passiert nichts, gibt es irgendeinen Weg in PHP, um ein Protokoll zu sehen, was kann passiert sein. –

+0

hat es nie gelöst –