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