PHP MYSQL dynamic select box

后端 未结 4 804
囚心锁ツ
囚心锁ツ 2021-01-16 12:14

I am trying to create a search box where the option selected from \'box1\' populates the options available for \'box2\'. The options for both boxes are given from my MYSQL d

4条回答
  •  天命终不由人
    2021-01-16 12:23

    You should try this;

    search.php

    ' . $school['name'] . '';
        }
    }
    // The user selected a school and now we will send back a JSON array with products, belonging to the specified school
    else {
        $school = mysqli_real_escape_string( $_GET['school'] );
        $sql_products = mysqli_query( $con, "SELECT `product` FROM products WHERE school = '{$school}'" );
        $products = array();
        while ( $product = mysqli_fetch_array( $sql_products ) ) {
            // Note: If you use array_push() to add one element to the array it's better to use $array[] = 
            // because in that way there is no overhead of calling a function.
            // http://php.net/manual/en/function.array-push.php
            $products[] = $product['product'];
        }
    
        header( "Content-Type: application/json" );
        echo json_encode( $products );
        die;
    }
    
    ?>
    

提交回复
热议问题