Jump to content

Call function/PHP reload every 5 seconds


RADaugherty
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.

 

Breakdown

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">


<head>

<!--                          Style for Tables              !-->

	<style>
* {
  box-sizing: border-box;
}

.row {
  display: flex;
  margin-left:-5px;
  margin-right:-5px;
}

.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;
}



	</style>
</head>

<body>
    

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

      $('.shipLineData').load('shipline.php');
      window.alert("test");
  }
</script>

    

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

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

</div>
</div>

		</div>
</body>


</html>

 

shipline.php w/ table creation

 

<?php

$servername = "localhost";
$username = "xxxx"; // User
$password = "xxxx";
$dbname = "xxxxx";
$results = array();
		    unset($results);
		    $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");
$stmt->execute();

$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>";
    
    $i++;
  }
  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.

 

image.png.915f98ab1ffb7a00df704d3cda9149d4.png

 

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.

Guest
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.