1

hi i wanna ask how can i call php function on every 5 sec i tried with this: This is my php

function php_func() {
    $link = mysql_connect("localhos", "SD_users", "users123");
    mysql_select_db("crazyde_SD_users", $link);
    $result = mysql_query("SELECT * FROM  `user` WHERE user1 = '".$_SESSION['username']."' ");
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        if($row['user2']!="none") {
            $new="ok";
        }
    }
    echo $new;
}

Below is my Js CODE :

window.setInterval(function(){
var result = "php_func();";
if(result =="ok") {
    alert(result);
} else
    alert("no"); 
}, 5000);

but it call the function only one time when i load the file i think i can do it with Ajax but i don't know how

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
KRIS
  • 11
  • 3

0 Answers0