My Problem is trying to display value from the database without refreshing the page.
Ok, My Code consist of value retrieve from page 1 to page 2 using GET methods, let's say the value is captured from the data-name "location" which consist of the value of 3.
The value of "location" on page 2 is then used to grab the information of the user on which location is stored and display the data that needs to display on a table on page 2 without clicking any button, basically on page load, it will display the data.
Then to make the data automatically update without refresh, I tried using a method that needs me to use Ajax that uses a GET to page 3 which supposedly have all the PHP to select database MySQL scripts.
In the PHP to select database MySQL scripts, my codes require to use the "location" data from page 2 that retrieve from page 1.
Since I need to POST using an ajax script, I added a PHP script into my Ajax script with a return value from page 3 data as well.
But it does not show the value that needs to be shown. Your help or guidance is highly appreciated. Thank You in advance.
Here are my codes for Page 2 (display page)
$locationID = @$_GET['location'];
$sqlCheckVisitors = "SELECT * FROM visitor_list WHERE visitor_EventChooseID = '$locationID'";
$resultCheckVisitors = $conn->query($sqlCheckVisitors);
$calCheckResult_visitor = mysqli_num_rows($resultCheckVisitors);
if($calCheckResult_visitor > 0)
{
$value_originalVisit = $calCheckResult_visitor;
}
else
{
$value_originalVisit = 0;
}
<div class="row">
<div class="form-group col">
<label class="form-control form-control-lg text-8 text-center">Live Balance : <br>
<div id="live_totalbalance"></div>
/
<div id="live_totalpreset"></div>
</label>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
// Display Total Live Balance
$.ajax({
url: "livedata_totalbalance.php?locationID=<?php echo $locationID ;?>",
type: "GET",
dataType: "html",
cache: "false",
success: function(data)
{
$('#live_totalbalance').html(data);
}
});
});
</script>
Here are my codes for Page 3 (livedata_totalbalance.php)
<?php
include "database.php";
$locationID = @$_GET['locationID'];
$sqlEventList = "SELECT * FROM event_list WHERE event_id ='$locationID'";
$resultEventList = $conn->query($sqlEventList);
$dataEventList = mysqli_fetch_array($resultEventList);
$event_data = $dataEventList['event_data'];
echo $event_data;
?>