Jump to content

Call function/PHP reload every 5 seconds

Go to solution Solved by requinix,

Recommended Posts

Not sure the best place to post this but seeing as the actual hiccup seems to be in the JS side of the call I'm throwing it here.



1: Page Loads

2: Set interval to call Div of "shipLineData" to update MySQL Table data

3: Load initial Div/Data (Can see all the table info) - Added in a "test1" echo at the bottom so I can just change that without having to change MySQL data to test refresh

4: Nothing happens (Added alert box for testing, it never fires)

5: Can remove the "$('.shipLineData').load('shipline.php');" from the function and now the alert box shows up.


Index page

<!DOCTYPE html>
<html lang="en">


<!--                          Style for Tables              !-->

* {
  box-sizing: border-box;

.row {
  display: flex;

.column {
  flex: 50%;
  padding: 5px;

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  border: 1px solid #ddd;

th {
      text-align: left;
  padding: 16px;
  font-size: 130%;
  font-weight: bold;
  color: orange;

td {
      text-align: left;
  padding: 16px;
  font-size: 90%;
  font-weight: bold;

tr:nth-child(even) {
  background-color: #f2f2f2;
		caption {
    text-align: center;
    margin-bottom: 5px;
    font-size: 100%;
    padding: 5px;
    letter-spacing: 2px;
    font-weight: bold;



<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  setInterval( refreshTables, 5000 );
  var inRequest = false;
  function refreshTables() {



    <div class="shipLineData">
    <div class="row">
  <div class="column">

<?php include('shipline.php')?>





shipline.php w/ table creation



$servername = "localhost";
$username = "xxxx"; // User
$password = "xxxx";
$dbname = "xxxxx";
$results = array();
		    $results = array();

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

$stmt = $conn->prepare("SELECT SystemID, ServiceOrder FROM ServicePending");

$i = 0;
$stmt->bind_result($ID, $WO);
while ($stmt->fetch()) {
    $i += 1;
    $results[$i] = array('SystemID' => $ID,  'ServiceOrder' => $WO);

$count = count($results);

  $i = 1;
  echo "<table id='shipLineTable'>";
  echo "<tr>";
      echo "<caption>Ready to Ship</caption>";
    echo "<th>Serial Number</th>";
    echo "<th>Work Order Number</th>";
    echo "</tr>";
  while ($i < $results && $i < $count + 1) {
    echo "<tr>";

    echo "<td>" . $results[$i]["SystemID"] . "</td>";
    echo "<td>" . $results[$i]["ServiceOrder"] . "</td>";
    echo "</tr>";
  echo "</table>";
  echo "test1";



Link to comment
Share on other sites

6 hours ago, requinix said:

Any errors in the browser console? Can you see in the developer console the browser making a network request to shipline.php?

Hello! No I don't see any errors. I am using GoDaddy with CPanel so as far as I know the only information I get is in the "error_log" file it generates if theres an error but nothing is written in there. 


I'm a dope, I am just now learning web development so I didn't realize Chrome had a built in console viewer.




This is being thrown, I'll dig into it and see if I can figure out why!


Looks like I needed to add in the reference to JQuery is all! Added that in and I'm now seeing the alertbox so I'll keep testing!


As of right now it says I am updating the data but if I change my test echo from shipline.php I don't get that change until I manually refresh the page.

Edited by RADaugherty
Cause I'm an idiot
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.