Flashing image in Chrome

Asked

Viewed 268 times

0

I upload a PHP file that brings me an image in jpg. Code:

<?php
$url = "http://site.com.br/sistema/";
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('arquivo.php').fadeIn("slow");
}, 1000); // refresh every 10000 milliseconds
</script>

<div id="load_tweets">
</div>

php file is like this:

<?php
$conecta = mysql_connect('localhost','teste','teste')or die(mysql_error());
$banco = mysql_select_db('nomeBanco');

$selecionaTabela = mysql_query("SELECT * FROM noticias WHERE id = '187'")or die(mysql_error());
$dados = mysql_fetch_array($selecionaTabela);
?>

<img src="modulos/upload/<?php echo $dados['fotoEvento'];?>" alt=""/>

But in Chrome the image keeps flashing, already in Mozilla no!

  • It’s the same as Facebook, when you publish something, the photo of the person who posted the news appears, and the content below...but the photo of the person is flashing in Chrome

  • I put an ORDER BY id DESC...when new news comes, will appear first, same as Facebook Internet. It’s a Timeline system that I created, but the problem is that the image of the profile of the person who posted the news is flashing in Chrome. Flasher why set 1000 milliseconds

  • These id is coming from a single table of mysql called (noticas) everything that is registered in this table, will appear in Timeline

  • Anyway, do not replace all the contents of the #load_tweets once a second. Search only for new content, and enter at the end of the div if there is any. This should solve the problem. I also recommend using a range greater than 1 second for verification.

  • Excuse the ignorance, but how can I know if there is a new content register in this table?

  • It depends on the structure of your table. If you have a date/time field, you can rely on it. Or a unique id for each table row. Note: I will delete some of my old comments, to give a clean question.

Show 1 more comment

1 answer

0


Be that as it may, do not replace all the contents of the div #load_tweets once a second. Only search for new content, and enter at the end of the div if there is.

I do not know exactly what the purpose of its application, but the most common is exactly what bfavaretto spoke: display only new content. For this:

1) Where a new content is inserted in the hardcore bank a insertion date.

2) Each access to the ".php file" record the date/time of access in the user’s session.

The information 1 and 2 will allow you to know when the content was entered and which was the last time the user uploaded the content. Just consult only content whose insertion date is longer than the date the user last loaded the contents.

Ex:

$ultimaVisita = empty($_SESSION['ultimaVisita'])?'0000-00-00 00:00:00':$_SESSION['ultimaVisita'];


$selecionaTabela = mysql_query("SELECT * FROM noticias WHERE id = '187' AND data_insersao > '".$ultimaVisita."'")or die(mysql_error());
$dados = mysql_fetch_array($selecionaTabela);

$_SESSION['ultimaVisita'] = Date('Y-m-d H:i:s');
  • Thank you all!!! You can solve the problem there!!! Thank you very much!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.