RADaugherty Posted September 29, 2022 Share Posted September 29, 2022 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/315387-call-functionphp-reload-every-5-seconds/ Share on other sites More sharing options...
Solution requinix Posted September 29, 2022 Solution Share Posted September 29, 2022 Any errors in the browser console? Can you see in the developer console the browser making a network request to shipline.php? Quote Link to comment https://forums.phpfreaks.com/topic/315387-call-functionphp-reload-every-5-seconds/#findComment-1601196 Share on other sites More sharing options...
RADaugherty Posted September 30, 2022 Author Share Posted September 30, 2022 (edited) 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 September 30, 2022 by RADaugherty Cause I'm an idiot Quote Link to comment https://forums.phpfreaks.com/topic/315387-call-functionphp-reload-every-5-seconds/#findComment-1601209 Share on other sites More sharing options...
RADaugherty Posted September 30, 2022 Author Share Posted September 30, 2022 Idiot 2.0 I had <div class="shipLineData"> Instead of <div id="shipLineData"> And a . instead of # here $('.shipLineData').load('shipline.php'); -> $('#shipLineData').load('shipline.php'); All seems to be working now! Quote Link to comment https://forums.phpfreaks.com/topic/315387-call-functionphp-reload-every-5-seconds/#findComment-1601210 Share on other sites More sharing options...
RADaugherty Posted September 30, 2022 Author Share Posted September 30, 2022 I'm going to mark this as solved for now! Thanks for leading me in the right direction requinix! A good start to my website I think! Quote Link to comment https://forums.phpfreaks.com/topic/315387-call-functionphp-reload-every-5-seconds/#findComment-1601212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.