1

如果我想在 sql server 2000 中显示来自一个数据库的数据,那么我编写这样的 php 脚本:

<?php
// connect to db branch
include "connect_dbbranch.php"
//example query
$kueri = "SELECT TOP 20 COUNT(ID) AS ID, SUM(NILAI) AS NILAI FROM table WHERE tgl =   
'09/01/2013' " ORDER BY NILAI DESC
$do=mssql_query($kueri);
//looping
while($result=mssql_fetch_array($do)){
 echo "$result[ID]<br>";
 echo "$result[NILAI]<br>"; 
}
?>

如果上面的脚本运行,它将按 DESC NILAI 显示 20 个数据顺序。现在我想通过 DESC NILAI 显示 20 个数据顺序,就像上面的脚本一样,但是来自所有数据库分支。

这是我的逻辑和脚本(它不显示 20 个数据,而是 113 个):

<?php
// connect ip server
include "../../../config/dball.php";
// select database name
$branch = mssql_query("SELECT NM_DATA, NM_BRANCH FROM Branch ORDER BY KD_BRANCH ASC");
while ($allbranch = mssql_fetch_array($branch)){
  //connect for each database
  include "../../../config/db.php";
  mssql_select_db($allbranch[NM_DATA]);

  //example query for selecting data
  $kueri = "SELECT TOP 20 COUNT(ID) AS ID, SUM(NILAI) AS NILAI
  FROM table WHERE tgl = '09/01/2013' " ORDER BY NILAI DESC
  $do=mssql_query($kueri);
  //looping
  while($result=mssql_fetch_array($do)){
   echo "$result[ID]<br>";
   echo "$result[NILAI]<br>";
  }
} // END LOOPING ALL BRANCH
?>

如何解决这个问题,这样我就可以从所有数据库分支中获取 20 个数据?

4

0 回答 0