I have several div tags that I would like to be updated with several different mysql queries.
My code below only updates one of these divs, how can I expand it to 1-6 and also leave room for expansion in the future for more divs?
I also need to be able to update each div individually with a specific query for a specific table.
<html>
<div id="1"> </div>
<div id="2"> </div>
<div id="3"> </div>
<div id="4"> </div>
<div id="5"> </div>
<div id="6"> </div>
//...and so on
</html>
<script type="text/javascript">
$(document).ready(function () {
function display($id) {
$.ajax({
async: false,
type: "POST",
url: "apifile.php",
data: {id:$id},
dataType: "json",
success: function(msg) {
if(msg.success) {
$($id).next(".one").html(msg);
} else {
alert("error");
}
}
});
}
</script>
<?php
mysql_connect(host, user, pass);
mysql_select_db(name);
mysql_query("select round((count(*)*100)/(select count(*) from test),1) as percent from test group by field1 order by percent desc");
$reply['success'] = "Success";
if($return = display($id)) {
$reply['success'] = "Success";
} else {
$reply['error'] = "Error";
}
echo json_encode($reply);
?>