Update data automatically without refreshing the page

0

Maybe this doubt is pretty "beast", but I have tried in different ways and I can not. I have a page that counts a number of products, but I need the data presented through the query that is on the page, to be updated every 1 second without the page being updated. I tried some solutions in Ajax and JS, but I could not. :

Does anyone have any tips on how I can do this? Here is the php code I'm using:

$con = mysql_connect('localhost', 'root', 'password');
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}
$user = mysql_real_escape_string($user);
$pwd = mysql_real_escape_string($pwd);

mysql_select_db("fabrica", $con);

$sql="SELECT COUNT(codigo) FROM inclusao_codigo WHERE cod_linha = '1' AND cod_turno = '1' AND data = CURRENT_DATE AND erro_ean IS NULL'";

$total = mysql_query($sql);


<link rel="stylesheet" type="text/css" href="../css/rhino/sc_inettuts.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/gridstack.min.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/Sc9_Rhino_grid.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/Sc9_Rhino_gridLTR.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/Sc9_Rhino_container.css" />
<link rel="stylesheet" type="text/css" href="../css/rhino/Sc9_Rhino_containerLTR.css" />
<div style="display: inline-block">
<div class="widget-content widget-content-title-none scContainerIndexMoldura scContainerIndexMoldura_widget15" style="height: 100%" id="id-div-iframe-4">
<div style="text-align: center; padding-top: 15px">
   <div class="clearfix"><span style="font-size:20px; font-weight: bold;"><img src="../_lib/img/sys__NM__img__NM__certificate_full.png"><br>Total de Produtos</span></div>
   <div class="clearfix"><span style="float: right; font-size:15px;">Linha 1</span></div>
   <div class="clearfix"><span style="font-size:70px;"><?php echo $total; ?></span></div>
</div>
    
asked by anonymous 30.04.2018 / 15:14

1 answer

0
  

My_script.js

<script src="https://code.jquery.com/jquery-2.1.1.min.js"type="text/javascript"></script>
    <script>
    $(document).ready(function(){
        setInterval(function(){
            $("#count").load('meu_script_2.php')
        }, 1000);
    });
</script>

    

  

My_script_2.php

$con = mysql_connect('localhost', 'root', 'password');
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}
$user = mysql_real_escape_string($user);
$pwd = mysql_real_escape_string($pwd);

mysql_select_db("fabrica", $con);

$sql="SELECT COUNT(codigo) FROM inclusao_codigo WHERE cod_linha = '1' AND cod_turno = '1' AND data = CURRENT_DATE AND erro_ean IS NULL'";

$total = mysql_query($sql);
printf("%d",$total);
    
30.04.2018 / 15:39