At first, you’ll have to make a dropdown filled with your values from the database:
<select id="pakket">
<?php
foreach ($allPakkets as $pakket) {
echo '<option value="'.$pakket['id'].'">'.$pakket['name'].'</option>';
}
?>
</select>
And a div to put results in:
<div id="results"></div>
Now, we add a piece of javascript:
jQuery('#pakket').change(function(){ // when the dropdown changes...
var newvalue = jQuery('#pakket').val(); // get the new value
jQuery.ajax({
method: 'GET',
url: 'url-to-script.php',
data: {
newvalue: newvalue
}
}).done(function(response){ // after the request has been loaded...
jQuery('#results').html(response); // put the response in the div
});
});
Now the only thing you have to do is make a url-to-script.php
which loads the properties of the value sent in $_GET['newvalue']
. The output of this PHP script will be placed in the div#results
.