2016-05-15 8 views
0

私はphpMyAdmin idコールに1または0の整数値を持つカラムを持っています。どのようにしてユーザーがOKをクリックしてmsgを0に更新するかを指定する方法は?アラートが表示されたときにデータベースにデータを更新します。

index.htmlを

<!DOCTYPE html> 
<html> 
<body> 

<h1>Getting server updates</h1> 
<div id="result"></div> 

<script> 
if(typeof(EventSource) !== "undefined") { 
    var source = new EventSource("demo_sse.php"); 

    source.onmessage = function(event) { 
     var msg = event.data; 
     if (msg>0){  
     alert('Welcome'); 
     }; 
    }; 
}; 
</script> 

</body> 
</html> 

demo_sse.php

<?php 

$dominio = "127.0.0.1"; 
$host = "localhost"; 
$user = "root"; 
$pass = ""; 
$banco = "teste"; 
$codificacao = 'utf8'; 

$conexao = mysqli_connect($host, $user, $pass, $banco) or die(mysqli_connect_error()); 

$sql= "select * from `msg`"; 

$resultado = mysqli_query($conexao,$sql); 
$tabela = mysqli_fetch_array($resultado); 
$id=$tabela['id']; 


header('Content-Type: text/event-stream'); 
header('Cache-Control: no-cache'); 

$time = date('r'); 
echo "data:{$id}\n\n"; 
flush(); 

?> 
+0

質問の内容を明確にし、何をしようとしているのか、どこに問題があるのか​​を示すコードを入力する必要があります。 – fvgs

答えて

0

あなたはクリックのイベントを使用し、その後0にそのレコードを切り替えPHPスクリプトを作成する必要がありますOKボタンを押すと、そのスクリプトに対するAjaxリクエストが発生します。 AjaxはあなたのPHPを実行し、あなたが望む効果を与えるでしょう。あなたがより多くの指導を必要とするなら、私はコンピュータに着くときの詳細な例をすることができます。

+0

私に例を教えてもらえますか?私はまだAjaxを初めて使っています –

関連する問題