1

I'm trying to make a website that when you click the application it opens it and it works at the moment but opens every single application, which obviously i don't want.

I believe i need to put a foreach loop so for every application it puts a different$appLocation` in?

This is just a first project for me so maybe if someone can point me in the right direction.

<?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
        }
?>
1
  • firstly - don't run the query twice, remove $select_posts = mysqli_query($conn, $appQuery); and as the buttons are all named the same clicking any one of them will trigger ALL apps to launch Commented Oct 17, 2016 at 7:51

1 Answer 1

1

You could try along these lines bearing in mind my previous comments

<?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>
Sign up to request clarification or add additional context in comments.

1 Comment

sort of working but it's not responding when i click my applications now nothing happens, is there any way in php to see a log of what can be happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.