2016-10-17 300 views
1

我試圖做一個網站,當你點擊應用程序它打開它,它現在工作,但打開每一個應用程序,顯然我不想要。PHP - 雖然循環查詢

我相信我需要把foreach loop so for every application it puts a different $ appLocation`放入?

這對我來說只是第一個項目,所以也許如果有人能指出我正確的方向。

<?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

首先 - 不要運行該查詢兩次,去掉'$ select_posts = mysqli_query($康恩,$ appQuery);'並作爲按鈕都命名爲相同的點擊其中任何一個將觸發所有應用程序啓動 – RamRaider

回答

1

你可以沿着這些線路銘記盡我以前的評論

<?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

排序工作,但它沒有響應時,我點擊我的應用程序現在什麼都沒有發生,是否有任何方式在PHP中看到什麼可以記錄正在發生。 –

+0

沒有解決它 –