0

だから、これは私のコードです:

<?php
//Connect to the database
include("config.php");

//Query the database and get the count  
$result = mysql_query("SELECT * FROM ads");  
$num_rows = mysql_num_rows($result);  
?>

数秒ごとにデータベースにクエリを実行するようにするにはどうすればよいですか?

4

1 に答える 1

4

PHPスクリプトを個別に保存します(私の例では、thescript.phpの下にあります)

<?php

  //Connect to the database
  include("config.php");

  //Query the database and get the count 
  $q = mysql_query("SELECT count(*) as num FROM ads");
  $count = mysql_fetch_result($q,0,'num');
  echo $count; 

?>

次に、home.phpファイルでAJAX / javascript/jQueryを使用します。

 <script>
    $(function(){
      function loadNum()
      {  
        $('h1.countdown').load('thescript.php');
        setTimeout(loadNum, 5000); // makes it reload every 5 sec
      }
      loadNum(); // start the process...
    });
 </script>
于 2012-11-20T23:05:20.990 に答える