PHP-While循环查询

PHP-While循环查询,php,foreach,Php,Foreach,我正在尝试创建一个网站,当你点击应用程序时,它会打开它,它会立即工作,但会打开每个应用程序,这显然是我不想要的 我认为我需要设置一个foreach循环,这样对于每个应用程序,它都会设置一个不同的$appLocation`in 这只是我的第一个项目,如果有人能给我指出正确的方向 <?php $appQuery = "SELECT app_name, app_location, app_status, app_image FROM applications"; $select

我正在尝试创建一个网站,当你点击应用程序时,它会打开它,它会立即工作,但会打开每个应用程序,这显然是我不想要的

我认为我需要设置一个foreach循环,这样对于每个应用程序,它都会设置一个不同的$appLocation`in

这只是我的第一个项目,如果有人能给我指出正确的方向

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

你可以按照这些思路来尝试,记住我以前的评论

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

首先-不要运行两次查询,删除$select\u posts=mysqli\u query$conn,$appQuery;由于所有按钮的名称都相同,单击其中任何一个按钮都会触发所有应用程序启动某种工作状态,但当我单击我的应用程序时它没有响应现在什么都没有发生,php中是否有任何方法可以查看可能发生的事情的日志。