what my goal is to use AJAX to call my php function:
function getAns($mysqli)
{
$stmt = $mysqli->prepare('
SELECT `user_id`,`user_name`, `user_ans`
FROM `tbl_user`
WHERE `user_ans` != ""');
$stmt->execute();
$stmt->bind_result($id, $user, $ans);
$O ="";
$x = 1;
$O.="<table><form action=\"#\" method=\"POST\">";
while($stmt->fetch())
{
if($x%2)
{
$O.= "<tr>
<td>".$user."</td><td>".$ans."</td><td><input id=".$id." type=\"submit\" name=\"pts\" href=\"#\" value=\"+\"></td>
</tr>";
$x++;
}
else
{
$O.= "<tr>
<td>".$user."</td><td>".$ans."</td><td><input id=".$id." type=\"submit\" name=\"pts\" href=\"#\" value=\"+\"></td>
</tr>";
$x++;
}
}
$O.= "</form></table>";
// close statement
$stmt->close();
return $O;
}
at a set time interval,say every 5 seconds, using AJAX/jQuery. I am trying to have an answer section, which is in a div, auto grab things from my database and echo them onto the page.
My HTMLthat i was trying to have them put into looks like this:
<div id="ans" class="box3"><!--PHP Students answers -->
<form id="ans" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<?php echo getAns($mysqli);?>
</form>
</div>
I understand a little bit how it works but I don't understand the code it takes to get there. I am new to JavaScript/jQuery/AJAX but I am trying to use more of it in my code, so if anyone could elaborate it would be much appreciated, thanks!
setInterval.$Oisn't a good variable name. Instead, use something like$html_output