Well I personally have an ajax script making requests every 1 second to my database to show new content that has been published in the database however I am finding a problem this content always has a form per with a%
Script
<script>
//LISTA POSTS ESTABELECIMENTOS
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
$('#mostra_posts').load('ajax/mostra_posts.php?id_estabelecimento=<?php echo $row->id; ?>');
}, 1000); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]>
</script>
<?php
session_start();
require_once("../gtm/bd/funcoes.php");
ligarBd();
$id_estabelecimento = $_REQUEST['id_estabelecimento'];
$result_post=mysql_query("select * from posts where estabelecimento_id='".$id_estabelecimento."' order by data desc");
while($row_posts=mysql_fetch_object($result_post)){
$result_user_anex=mysql_query("select * from users_social where id='".$row_posts->user_id."'");
$row_user_anex=mysql_fetch_object($result_user_anex);
?>
<section class="container" style="margin:15px 0px 0px 0px; border-top-left-radius: 2px; border-top-right-radius: 2px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<div style="float:left; margin:0px 0px 10px 0px; "><img width="50" height="50" src="<?php echo $row_user_anex->user_foto ?>"/></div>
<h3 style="float:left; margin:15px 0px 0px 10px;"><?php echo utf8_encode($row_user_anex->fb_nome); ?></h3>
</td>
</tr>
</table>
<p><?php echo utf8_encode($row_posts->opiniao); ?></p>
<script>
FB.init({ appId: '1404139796547995', status: true, cookie: true, xfbml: true, oauth: true });
function post_fb<?php echo $row_posts->id_post; ?>() {
FB.login(function(response) {
if (response.authResponse) {
FB.ui({
method: 'feed',
message : "Vê este comentário sobre <?php echo $row_cat->titulo; ?> no @SabeOnde",
link : '<?php echo $row->link_site; ?>',
picture : 'http://sabeonde.pt/gtm/anexos/capa/<?php echo $row_capa->id_anexo; ?>.<?php echo $row_capa->tipo ?>',
name : '<?php echo $row_cat->titulo; ?> | SabeOnde',
from: '<?php echo $_SESSION['FBID'] ?>',
description : '<?php echo $row_posts->opiniao; ?>'
},
function(response) {
if (response && response.post_id) {
alert('Comentário Partilhado com sucesso!');
} else {
alert('Falha ao partilhar o comentário');
}
});
} else {
alert('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_actions, publish_stream'});
return false;
}
</script>
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#">Gosto</a></div>
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#" >Comentar</a></div>
<div style="float:left; margin:0px 5px 10px 0px;"><a href="#" onClick="post_fb<?php echo $row_posts->id_post; ?>()">Partilhar</a></div>
</section>
<?php
}
?>