-1
I have a database with a table conversations,it has the following attributes:
- transmitter
- receiver
- hora_msg
- message
- id
I need that as soon as a user sends a message ,update the receiver page,
$sql = "SELECT * FROM conversas WHERE transmissor LIKE '$transmissor' AND receptor LIKE '$receptor' OR receptor LIKE '$transmissor' AND transmissor LIKE '$receptor'";
$result = mysqli_query($connect,$sql);
echo "<table><thead></thead>
<tbody>";
if($linhas = mysqli_num_rows($result) > 0){
$teste = mysqli_affected_rows($connect);
while($row = mysqli_fetch_array($result)){
$mensagem = $row['mensagem'];
$rec = $row['receptor'];
$hora = $row['hora_msg'];
$id = $row['id'];
$hora = preg_replace('/:00.0000/',"",$hora);
$ultimaMsg = strtotime($hora);
$classe = "";
$result2 = mysqli_query($connect,$sql);
while($l = mysqli_fetch_array($result2) > 0){
$hora2 = $l['hora_msg'];
$hora2 = preg_replace('/:00.0000/',"",$hora2);
$ultMsg = strtotime($hora2);
if($ultMsg > $ultimaMsg){
header("Refresh: 0; url = cnv.php");
}
}
echo "<div class='invisivel'>$id</div>";
if($rec === $transmissor)$classe = 'receptor';
else $classe = 'transmissor';
$mensagem = base64_decode($mensagem);
if(preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$mensagem))
echo "<tr class='sms'><td><div class=$classe><div class='hora'>$hora</div><a href='$mensagem' target='blank'>$mensagem</a></div></td></tr>";
else
echo "<tr class='sms'><td><div class=$classe><div class='hora'>$hora</div>$mensagem </div></td></tr>";
}
echo "</tbody>
</table>";
}
But I did not get the expected result, what I need is that once something is inserted in the database the page is updated.
Friend, you’ve heard of Nodejs; undoubtedly, this format is not indicated to solve this type of problem
– Leonardo Negrão
Yes, I do,?
– mecatrônica com reciclagem