2016-10-17 241 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

没有解决它 –