I am trying to load mysql data into a div in a php page. But I want this data to stay up-to-date and refreshed every 10 seconds or so.
I looked online and followed several tutorials but I don't know what I am doing wrong.
Below is the php script that gets the data from DB and displays in a table.
<?php
require "conn.php";
$query = "SELECT * FROM turns where attended = 0";
$waiting = $conn->query($query);
if ($waiting->num_rows > 0)
{
echo "<table width='80%'><tr>";
echo "<th> Customer Number </th>";
echo "<th> Waiting Since </th> </tr>";
// output data of each row
while($row = $waiting->fetch_assoc())
{
$client = $row["id"];
$waitingSince = $row ["created_time"];
echo "<tr><td align='center'>".$client."</td>";
echo "<td align='center'>".$waitingSince."</td></tr>";
}
}
?>
I have been trying to load that file into another page div, but all I am getting is blank.
here is the other page attend.php:
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
function updateDiv()
{
$("#result").load("fetchLine.php");
}
</script>
</head>
<body>
<div id="result" style="border:solid 2px red; width: 100%;">
</div>
</body>
</html>
I have been trying to load the content first before adding the interval refresh function. Both attend.php and fetchLine.php are in the same directory