I'd like to query a database and upload entries from that database into fields on a webpage. However, the only way I currently know to do that is create a webpage in PHP that performs the query, prints it onto a page in a readable fashion, and then load that page with ajax and parse through the HTML. That seems like a very roundabout way of doing it-- so is there anything I can do which is more direct?
To be clear: I have a dropdown menu:
<select name="items" id="items" size=[php variable] onChange="javascript:updatePage()">
<option value="[database entry ID]">[php variable]</options>
<option value="[database entry ID]">[php variable]</options>
<textarea name="stuff" id="stuff">
</textarea><br>
And then later on I'll have:
<script src="jquery.js"></script>
<script>
function updatePage()
{
var itemToLoad = $('#items').val();
$.ajax({
type: "POST",
url: 'updatepage.php',
data: "itemtoload=" + itemToLoad,
success: function(data) {
var stuff = data;
stuff = parseWhatINeed(stuff);
$('#stuff').text(stuff);
}
});
}
</script>
And updatepage.php does a MySQL query, and the parseWhatINeed function parses what I need from the html in the data variable. Is there a better way of going about this?